diff mbox

gpio: Remove impossible checks on container_of() result

Message ID 20170109194744.24152-1-sboyd@codeaurora.org
State New
Headers show

Commit Message

Stephen Boyd Jan. 9, 2017, 7:47 p.m. UTC
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.

Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
 drivers/gpio/gpiolib.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Linus Walleij Jan. 11, 2017, 3:02 p.m. UTC | #1
On Mon, Jan 9, 2017 at 8:47 PM, Stephen Boyd <sboyd@codeaurora.org> wrote:

> 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.
>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

Good point.

Patch applied.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 86bf3b84ada5..4864408364ef 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;
 }