hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mcb/mcb-pci.c
....@@ -31,7 +31,7 @@
3131 {
3232 struct resource *res;
3333 struct priv *priv;
34
- int ret;
34
+ int ret, table_size;
3535 unsigned long flags;
3636
3737 priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL);
....@@ -90,7 +90,30 @@
9090 if (ret < 0)
9191 goto out_mcb_bus;
9292
93
- dev_dbg(&pdev->dev, "Found %d cells\n", ret);
93
+ table_size = ret;
94
+
95
+ if (table_size < CHAM_HEADER_SIZE) {
96
+ /* Release the previous resources */
97
+ devm_iounmap(&pdev->dev, priv->base);
98
+ devm_release_mem_region(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE);
99
+
100
+ /* Then, allocate it again with the actual chameleon table size */
101
+ res = devm_request_mem_region(&pdev->dev, priv->mapbase,
102
+ table_size,
103
+ KBUILD_MODNAME);
104
+ if (!res) {
105
+ dev_err(&pdev->dev, "Failed to request PCI memory\n");
106
+ ret = -EBUSY;
107
+ goto out_mcb_bus;
108
+ }
109
+
110
+ priv->base = devm_ioremap(&pdev->dev, priv->mapbase, table_size);
111
+ if (!priv->base) {
112
+ dev_err(&pdev->dev, "Cannot ioremap\n");
113
+ ret = -ENOMEM;
114
+ goto out_mcb_bus;
115
+ }
116
+ }
94117
95118 mcb_bus_add_devices(priv->bus);
96119