Skip to contentSkip to conversation

gpio: Remove impossible checks on container_of() result

PATCH In review Stephen Boyd 2 participants 2 messages Jan 9, 2017 – Jan 11, 2017 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: Remove impossible checks on container_of() result

container_of() does pointer math on the pointer that's passed in. If it were to return a NULL pointer the value passed in would need to be perfectly offset from 0 to make that so. Remove these checks because they don't make sense.

---
 drivers/gpio/gpiolib.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpio/gpiolib.c +1 -3
index 86bf3b84ada5..4864408364ef 100644
@@ -982,7 +982,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *filp)
 					      struct gpio_device, chrdev);
 
 	/* Fail on open if the backing gpiochip is gone */
-	if (!gdev || !gdev->chip)
+	if (!gdev->chip)
 		return -ENODEV;
 	get_device(&gdev->dev);
 	filp->private_data = gdev;
@@ -1001,8 +1001,6 @@ static int gpio_chrdev_release(struct inode *inode, struct file *filp)
 	struct gpio_device *gdev = container_of(inode->i_cdev,
 					      struct gpio_device, chrdev);
 
-	if (!gdev)
-		return -ENODEV;
 	put_device(&gdev->dev);
 	return 0;
 }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 6 lines · Stephen Boyd

container_of() does pointer math on the pointer that's passed in. If it were to return a NULL pointer the value passed in would need to be perfectly offset from 0 to make that so. Remove these checks because they don't make sense.

Good point.

Patch applied.

Yours,
Linus Walleij