Skip to contentSkip to conversation

add platform_data only if non NULL

PATCH In review Brian Harring 2 participants 2 messages Oct 4, 2010 – Oct 18, 2010 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add platform_data only if non NULL

If a NULL or 0 size platform_data is added, the underlying dup results in a pointer into nullspace- meaning drivers can't do null checks for platform_data.

This fixes an oops during probing for drivers/net/ks8842, and drivers/mmc/host/sdhci-pltform when the mfd is timberdale

---
 drivers/mfd/mfd-core.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
drivers/mfd/mfd-core.c +9 -4
index 1823a57..eee73a8 100644
@@ -38,10 +38,15 @@ static int mfd_add_device(struct device *parent, int id,
 	pdev->dev.parent = parent;
 	platform_set_drvdata(pdev, cell->driver_data);
 
-	ret = platform_device_add_data(pdev,
-			cell->platform_data, cell->data_size);
-	if (ret)
-		goto fail_res;
+	if (cell->data_size) {
+		ret = platform_device_add_data(pdev,
+				cell->platform_data, cell->data_size);
+		if (ret)
+			goto fail_res;
+	} else {
+		/* potentially nulled already, just being paranoid. */
+		pdev->dev.platform_data = NULL;
+	}
 
 	for (r = 0; r < cell->num_resources; r++) {
 		res[r].name = cell->resources[r].name;
Signature · 1 line
1.7.2
#1 lore raw

Hi Brian,

Quoted 4 lines · Brian Harring

If a NULL or 0 size platform_data is added, the underlying dup results in a pointer into nullspace- meaning drivers can't do null checks for platform_data.

This fixes an oops during probing for drivers/net/ks8842, and drivers/mmc/host/sdhci-pltform when the mfd is timberdale

Patch applied, without the paranoid setting :) Many thanks.

Cheers,
Samuel.

Quoted 32 lines
---
 drivers/mfd/mfd-core.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
drivers/mfd/mfd-core.c +9 -4
index 1823a57..eee73a8 100644
@@ -38,10 +38,15 @@ static int mfd_add_device(struct device *parent, int id,
 	pdev->dev.parent = parent;
 	platform_set_drvdata(pdev, cell->driver_data);
 
-	ret = platform_device_add_data(pdev,
-			cell->platform_data, cell->data_size);
-	if (ret)
-		goto fail_res;
+	if (cell->data_size) {
+		ret = platform_device_add_data(pdev,
+				cell->platform_data, cell->data_size);
+		if (ret)
+			goto fail_res;
+	} else {
+		/* potentially nulled already, just being paranoid. */
+		pdev->dev.platform_data = NULL;
+	}
 
 	for (r = 0; r < cell->num_resources; r++) {
 		res[r].name = cell->resources[r].name;
Signature · 1 line
1.7.2
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/