drivers: char: scx200_gpio: check return value of cdev_add()
Subsystems (2)
PATCH 1/1 drivers: char: scx200_gpio: check return value of cdev_add()
Check return value of cdev_add() and in case of error unregister the range of device numbers.
Signed-off-by Salah Triki <[email protected]>
--- drivers/char/scx200_gpio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/char/scx200_gpio.c +5 -1
@@ -107,10 +107,14 @@ static int __init scx200_gpio_init(void) }cdev_init (&scx200_gpio_cdev, &scx200_gpio_fileops); -cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); + rc =cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); +if (rc) + goto unregister_chrdev_region;return 0 ;/* succeed */ +unregister_chrdev_region: +unregister_chrdev_region (devid,MAX_PINS ); undo_platform_device_add:platform_device_del (pdev); undo_malloc:
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerQuoted 31 lines · Salah Triki
Check return value of
cdev_add()and in case of error unregister the range of device numbers.Signed-off-by Salah Triki <[email protected]>--- drivers/char/scx200_gpio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/char/scx200_gpio.c +5
-1@@ -107,10 +107,14 @@ static int __init scx200_gpio_init(void) }cdev_init (&scx200_gpio_cdev, &scx200_gpio_fileops); -cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); + rc =cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); +if (rc) + goto unregister_chrdev_region;return 0 ;/* succeed */ +unregister_chrdev_region: +unregister_chrdev_region (devid,MAX_PINS ); undo_platform_device_add:platform_device_del (pdev); undo_malloc:Signature · 1 line
2.43.0
How was this tested?
thanks,
greg k-h
Quoted 24 lines · Greg Kroah-Hartman
Quoted 23 lines · Salah Triki
Check return value of
cdev_add()and in case of error unregister the range of device numbers.Signed-off-by Salah Triki <[email protected]>--- drivers/char/scx200_gpio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/char/scx200_gpio.c +3
-1@@ -107,10 +107,14 @@ static int __init scx200_gpio_init(void) }cdev_init (&scx200_gpio_cdev, &scx200_gpio_fileops); -cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); + rc =cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); +if (rc) + goto unregister_chrdev_region;return 0 ;/* succeed */
Quoted 11 lines
Quoted 8 lines
drivers/char/scx200_gpio.c +2
-0+unregister_chrdev_region: +unregister_chrdev_region (devid,MAX_PINS ); undo_platform_device_add:platform_device_del (pdev); undo_malloc:Signature · 1 line
2.43.0How was this tested?
I only compiled it.
ST
Quoted 3 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 37 lines · Salah Triki
Quoted 24 lines · Greg Kroah-Hartman
Quoted 23 lines · Salah Triki
Check return value of
cdev_add()and in case of error unregister the range of device numbers.Signed-off-by Salah Triki <[email protected]>--- drivers/char/scx200_gpio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/char/scx200_gpio.c +3
-1@@ -107,10 +107,14 @@ static int __init scx200_gpio_init(void) }cdev_init (&scx200_gpio_cdev, &scx200_gpio_fileops); -cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); + rc =cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); +if (rc) + goto unregister_chrdev_region;return 0 ;/* succeed */ Quoted 11 lines
Quoted 8 lines
drivers/char/scx200_gpio.c +2
-0+unregister_chrdev_region: +unregister_chrdev_region (devid,MAX_PINS ); undo_platform_device_add:platform_device_del (pdev); undo_malloc:Signature · 1 line
2.43.0How was this tested?
Quoted 1 line
I only compiled it.
Please properly test it.