Re: [PATCH] char: scx200_gpio: check cdev_add() return value

From: Greg Kroah-Hartman

Date: Fri Jul 31 2026 - 08:28:28 EST


On Thu, Jul 30, 2026 at 05:53:21PM +0800, Linkai Gong wrote:
> cdev_add() can fail. The driver currently ignores the return value and
> reports probe success even when the cdev was not registered, leaving a
> chrdev region allocated with no working file operations.
>
> Check the return value, emit an error, and unwind the chrdev region and
> platform device on failure.
>
> Fixes: 635adb6cd25c ("[PATCH] scx200_gpio: use 1 cdev for N minors, not N for N")
> Signed-off-by: Linkai Gong <gonglinkai@xxxxxxxxxx>
> ---
> drivers/char/scx200_gpio.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
> index 700e6affea6f..d9d66d4c2312 100644
> --- a/drivers/char/scx200_gpio.c
> +++ b/drivers/char/scx200_gpio.c
> @@ -107,10 +107,16 @@ 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 < 0) {

Should just be:
if (rc) {

right?

thanks,

greg k-h