* [PATCH] drivers: char: scx200_gpio: check return value of cdev_add()
@ 2025-04-07 16:56 Salah Triki
2025-04-15 14:54 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Salah Triki @ 2025-04-07 16:56 UTC (permalink / raw)
To: Jim Cromie, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel; +Cc: salah.triki
Check return value of cdev_add() and in case of error unregister the
range of device numbers.
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/char/scx200_gpio.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index 700e6affea6f..36efcc828e8e 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -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:
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: char: scx200_gpio: check return value of cdev_add()
2025-04-07 16:56 [PATCH] drivers: char: scx200_gpio: check return value of cdev_add() Salah Triki
@ 2025-04-15 14:54 ` Greg Kroah-Hartman
2025-04-15 15:30 ` Salah Triki
0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2025-04-15 14:54 UTC (permalink / raw)
To: Salah Triki; +Cc: Jim Cromie, Arnd Bergmann, linux-kernel
On Mon, Apr 07, 2025 at 05:56:14PM +0100, Salah Triki wrote:
> Check return value of cdev_add() and in case of error unregister the
> range of device numbers.
>
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> ---
> drivers/char/scx200_gpio.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
> index 700e6affea6f..36efcc828e8e 100644
> --- a/drivers/char/scx200_gpio.c
> +++ b/drivers/char/scx200_gpio.c
> @@ -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:
> --
> 2.43.0
>
How was this tested?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: char: scx200_gpio: check return value of cdev_add()
2025-04-15 14:54 ` Greg Kroah-Hartman
@ 2025-04-15 15:30 ` Salah Triki
2025-04-15 16:01 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Salah Triki @ 2025-04-15 15:30 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Jim Cromie, Arnd Bergmann, linux-kernel
On Tue, Apr 15, 2025 at 04:54:38PM +0200, Greg Kroah-Hartman wrote:
> On Mon, Apr 07, 2025 at 05:56:14PM +0100, Salah Triki wrote:
> > Check return value of cdev_add() and in case of error unregister the
> > range of device numbers.
> >
> > Signed-off-by: Salah Triki <salah.triki@gmail.com>
> > ---
> > drivers/char/scx200_gpio.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
> > index 700e6affea6f..36efcc828e8e 100644
> > --- a/drivers/char/scx200_gpio.c
> > +++ b/drivers/char/scx200_gpio.c
> > @@ -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:
> > --
> > 2.43.0
> >
>
> How was this tested?
>
I only compiled it.
ST
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: char: scx200_gpio: check return value of cdev_add()
2025-04-15 15:30 ` Salah Triki
@ 2025-04-15 16:01 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2025-04-15 16:01 UTC (permalink / raw)
To: Salah Triki; +Cc: Jim Cromie, Arnd Bergmann, linux-kernel
On Tue, Apr 15, 2025 at 04:30:08PM +0100, Salah Triki wrote:
> On Tue, Apr 15, 2025 at 04:54:38PM +0200, Greg Kroah-Hartman wrote:
> > On Mon, Apr 07, 2025 at 05:56:14PM +0100, Salah Triki wrote:
> > > Check return value of cdev_add() and in case of error unregister the
> > > range of device numbers.
> > >
> > > Signed-off-by: Salah Triki <salah.triki@gmail.com>
> > > ---
> > > drivers/char/scx200_gpio.c | 6 +++++-
> > > 1 file changed, 5 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
> > > index 700e6affea6f..36efcc828e8e 100644
> > > --- a/drivers/char/scx200_gpio.c
> > > +++ b/drivers/char/scx200_gpio.c
> > > @@ -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:
> > > --
> > > 2.43.0
> > >
> >
> > How was this tested?
> >
>
> I only compiled it.
Please properly test it.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-15 16:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07 16:56 [PATCH] drivers: char: scx200_gpio: check return value of cdev_add() Salah Triki
2025-04-15 14:54 ` Greg Kroah-Hartman
2025-04-15 15:30 ` Salah Triki
2025-04-15 16:01 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox