linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: linux@armlinux.org.uk, jirislaby@kernel.org,
	andre.przywara@arm.com, linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: pl011: Fix error handling in pl011_init()
Date: Wed, 9 Nov 2022 10:10:08 +0100	[thread overview]
Message-ID: <Y2tucFPU15TsbRBp@kroah.com> (raw)
In-Reply-To: <20221109084626.2032013-1-cuigaosheng1@huawei.com>

On Wed, Nov 09, 2022 at 04:46:26PM +0800, Gaosheng Cui wrote:
> When amba_driver_register failed, we need to unregister the platform
> driver which have been registered, otherwise there maybe resource leak,
> so we add error handlings in pl011_init() to fix it.
> 
> Fixes: 0dd1e247fd39 ("drivers: PL011: add support for the ARM SBSA generic UART")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
>  drivers/tty/serial/amba-pl011.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
> index 6d8552506091..ef6d9941f972 100644
> --- a/drivers/tty/serial/amba-pl011.c
> +++ b/drivers/tty/serial/amba-pl011.c
> @@ -2982,11 +2982,23 @@ static struct amba_driver pl011_driver = {
>  
>  static int __init pl011_init(void)
>  {
> +	int ret;
> +
>  	printk(KERN_INFO "Serial: AMBA PL011 UART driver\n");
>  
> -	if (platform_driver_register(&arm_sbsa_uart_platform_driver))
> +	ret = platform_driver_register(&arm_sbsa_uart_platform_driver);
> +	if (unlikely(ret)) {

Only use likely/unlikely if you can prove with a benchmark that it makes
a measurable change to do so.

Here, on the init error path, it will never happen.

And how are you causing this call to fail?

How was this tested?

>  		pr_warn("could not register SBSA UART platform driver\n");
> -	return amba_driver_register(&pl011_driver);
> +		return ret;
> +	}
> +
> +	ret = amba_driver_register(&pl011_driver);
> +	if (unlikely(ret)) {

Again, never use unlikely() like this.

And again, how did you get this to fail under normal operation?  And how
was this tested?

thanks,

greg k-h

      reply	other threads:[~2022-11-09  9:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  8:46 [PATCH] serial: pl011: Fix error handling in pl011_init() Gaosheng Cui
2022-11-09  9:10 ` Greg KH [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=Y2tucFPU15TsbRBp@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=andre.przywara@arm.com \
    --cc=cuigaosheng1@huawei.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).