Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpiolib: fix device_create() result check

In case of failure, device_create() returns not NULL but the error code.
The current code checks for non-NULL though which causes kernel oops in
sysfs_create_group() when device_create() fails. Check for error using
IS_ERR() and propagate the error value using PTR_ERR() instead of fixed
-ENODEV code returned now...

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Sergei Shtylyov and committed by
Linus Torvalds
d62668e1 bcb3a167

+4 -4
+4 -4
drivers/gpio/gpiolib.c
··· 661 661 662 662 dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), 663 663 desc, ioname ? ioname : "gpio%d", gpio); 664 - if (dev) { 664 + if (!IS_ERR(dev)) { 665 665 if (direction_may_change) 666 666 status = sysfs_create_group(&dev->kobj, 667 667 &gpio_attr_group); ··· 679 679 if (status != 0) 680 680 device_unregister(dev); 681 681 } else 682 - status = -ENODEV; 682 + status = PTR_ERR(dev); 683 683 if (status == 0) 684 684 set_bit(FLAG_EXPORT, &desc->flags); 685 685 } ··· 800 800 mutex_lock(&sysfs_lock); 801 801 dev = device_create(&gpio_class, chip->dev, MKDEV(0, 0), chip, 802 802 "gpiochip%d", chip->base); 803 - if (dev) { 803 + if (!IS_ERR(dev)) { 804 804 status = sysfs_create_group(&dev->kobj, 805 805 &gpiochip_attr_group); 806 806 } else 807 - status = -ENODEV; 807 + status = PTR_ERR(dev); 808 808 chip->exported = (status == 0); 809 809 mutex_unlock(&sysfs_lock); 810 810