Skip to contentSkip to conversation

extcon: palmas: Fail gracefully if invalid configuration

PATCH In review Roger Quadros 2 participants 4 messages Dec 7, 2016 – Dec 8, 2016 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extcon: palmas: Fail gracefully if invalid configuration

extcon-palmas must be child of palmas and expects parent's drvdata to be valid. Check for non NULL parent drvdata and fail if it is NULL. Not doing so will result in a NULL pointer dereference later in the probe() parent drvdata is NULL (e.g. misplaced extcon-palmas node in device tree).

---
 drivers/extcon/extcon-palmas.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/extcon/extcon-palmas.c +5 -0
index 634ba70..ec987ab 100644
@@ -190,6 +190,11 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	struct palmas_usb *palmas_usb;
 	int status;
 
+	if (!palmas) {
+		dev_err(&pdev->dev, "device has invalid parent\n");
+		return -EINVAL;
+	}
+
 	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
 	if (!palmas_usb)
 		return -ENOMEM;
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Hi Roger,

Looks good to me.
But I have some comment.

How about changing the subject as following?

- old : Fail gracefully if invalid configuration
- new : Check the parent instance to prevent the NULL pointer error

Quoted 16 lines · Roger Quadros

extcon-palmas must be child of palmas and expects parent's drvdata to be valid. Check for non NULL parent drvdata and fail if it is NULL. Not doing so will result in a NULL pointer dereference later in the probe() parent drvdata is NULL (e.g. misplaced extcon-palmas node in device tree).

---
 drivers/extcon/extcon-palmas.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/extcon/extcon-palmas.c +0 -0
index 634ba70..ec987ab 100644

drivers/extcon/extcon-palmas.c static int palmas_usb_probe(struct platform_device *pdev) · line 194

Quoted 5 lines
drivers/extcon/extcon-palmas.c +2 -0
@@ -190,6 +190,11 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	struct palmas_usb *palmas_usb;
 	int status;
 
+	if (!palmas) {
+		dev_err(&pdev->dev, "device has invalid parent\n");

How about changing the error message as following?
because the extcon-palmas used the 'failed to ..' style for error message.
- "failed to get valid parent"

drivers/extcon/extcon-palmas.c static int palmas_usb_probe(struct platform_device *pdev) · line 200

Quoted 7 lines
drivers/extcon/extcon-palmas.c +3 -0
+		return -EINVAL;
+	}
+
 	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
 	if (!palmas_usb)
 		return -ENOMEM;

Best Regards,
Chanwoo Choi

#2 lore raw

Hi Chanwoo,

Quoted 9 lines · Chanwoo Choi

Hi Roger,

Looks good to me.
But I have some comment.

How about changing the subject as following?

- old : Fail gracefully if invalid configuration
- new : Check the parent instance to prevent the NULL pointer error

I'm OK with this.

Quoted 21 lines · Roger Quadros
Quoted 19 lines

extcon-palmas must be child of palmas and expects parent's drvdata to be valid. Check for non NULL parent drvdata and fail if it is NULL. Not doing so will result in a NULL pointer dereference later in the probe() parent drvdata is NULL (e.g. misplaced extcon-palmas node in device tree).

---
 drivers/extcon/extcon-palmas.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/extcon/extcon-palmas.c +0 -0
index 634ba70..ec987ab 100644
@@ -190,6 +190,11 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	struct palmas_usb *palmas_usb;
 	int status;
 
Quoted 6 lines

drivers/extcon/extcon-palmas.c static int palmas_usb_probe(struct platform_device *pdev) · line 194

Quoted 2 lines
drivers/extcon/extcon-palmas.c +2 -0
+	if (!palmas) {
+		dev_err(&pdev->dev, "device has invalid parent\n");

How about changing the error message as following?
because the extcon-palmas used the 'failed to ..' style for error message.
- "failed to get valid parent"

This is also fine.

I'll send a v2.

Quoted 10 lines

drivers/extcon/extcon-palmas.c static int palmas_usb_probe(struct platform_device *pdev) · line 200

Quoted 8 lines
drivers/extcon/extcon-palmas.c +3 -0
+		return -EINVAL;
+	}
+
 	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
 	if (!palmas_usb)
 		return -ENOMEM;

--
cheers,
-roger

#3 lore raw

PATCH v2 1/1 extcon: palmas: Check the parent instance to prevent the NULL

In reply to Roger Quadros

extcon-palmas must be child of palmas and expects parent's drvdata to be valid. Check for non NULL parent drvdata and fail if it is NULL. Not doing so will result in a NULL pointer dereference later in the probe() parent drvdata is NULL (e.g. misplaced extcon-palmas node in device tree).

---
Changelog:
v2:
- updated error message and commit message subject

 drivers/extcon/extcon-palmas.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/extcon/extcon-palmas.c +5 -0
index 634ba70..a128fd2 100644
@@ -190,6 +190,11 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	struct palmas_usb *palmas_usb;
 	int status;
 
+	if (!palmas) {
+		dev_err(&pdev->dev, "failed to get valid parent\n");
+		return -EINVAL;
+	}
+
 	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
 	if (!palmas_usb)
 		return -ENOMEM;
Signature · 1 line
2.7.4