The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Linkai Gong <gonglinkai@kylinos.cn>
Cc: Jim Cromie <jim.cromie@gmail.com>, Arnd Bergmann <arnd@arndb.de>,
	Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] char: scx200_gpio: check cdev_add() return value
Date: Fri, 31 Jul 2026 14:22:47 +0200	[thread overview]
Message-ID: <2026073136-good-manger-7c91@gregkh> (raw)
In-Reply-To: <20260730095321.2386744-1-gonglinkai@kylinos.cn>

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@kylinos.cn>
> ---
>  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

      reply	other threads:[~2026-07-31 12:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  9:53 [PATCH] char: scx200_gpio: check cdev_add() return value Linkai Gong
2026-07-31 12:22 ` Greg Kroah-Hartman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026073136-good-manger-7c91@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@osdl.org \
    --cc=arnd@arndb.de \
    --cc=gonglinkai@kylinos.cn \
    --cc=jim.cromie@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox