mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: maowenan <maowenan@huawei.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: <gregkh@linuxfoundation.org>, <jslaby@suse.com>,
	<linux-serial@vger.kernel.org>, <kernel-janitors@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] serial: sh-sci: Missing uart_unregister_driver() on error in sci_probe_single()
Date: Mon, 11 Mar 2019 22:29:06 +0800	[thread overview]
Message-ID: <50cd311c-651c-5c82-a3f4-8b1faf20110b@huawei.com> (raw)
In-Reply-To: <20190311124616.GE2412@kadam>



On 2019/3/11 20:46, Dan Carpenter wrote:
> On Mon, Mar 11, 2019 at 05:51:15PM +0800, Mao Wenan wrote:
>> Add the missing uart_unregister_driver() before return
>> from sci_probe_single() in the error handling case.
>>
>> Signed-off-by: Mao Wenan <maowenan@huawei.com>
>> ---
> 
> Sorry, I didn't really look at the code when I saw the v1 patch.
> 
> There are other error paths, but actually the whole approach is wrong.
> Please, read my google plus post about error handling:
> 
> https://plus.google.com/u/0/106378716002406849458/posts/1Ud9JbaYnPr
> 
OK.

> But then the other rule I didn't mention in that post which applies
> here is that the error handling should "mirror" the allocation code
> so if you have:
> 
> 	if (foo) {
> 		ret = allocate_one();
> 		if (ret)
> 			return ret;
> 	}
> 	ret = allocate_two();
> 	if (ret)
> 		goto free_one;
> 
> The error handling should mirror the "if (foo) " condition.  Like this:
> 
> free_one:
> 	if (foo)
> 		free_one();
> 
> Even if you can do extra analysis and find that the "if (foo) " can
> be removed, you should leave there, because the mirroring helps human
> readers.
> 
> In this case, the code is doing:
> 
> drivers/tty/serial/sh-sci.c
>   3259                  return -EBUSY;
>   3260  
>   3261          mutex_lock(&sci_uart_registration_lock);
>   3262          if (!sci_uart_driver.state) {
>                     ^^^^^^^^^^^^^^^^^^^^^^
>   3263                  ret = uart_register_driver(&sci_uart_driver);
>   3264                  if (ret) {
>   3265                          mutex_unlock(&sci_uart_registration_lock);
>   3266                          return ret;
>   3267                  }
>   3268          }
>   3269          mutex_unlock(&sci_uart_registration_lock);
>   3270  
> 
> We would have to mirror the "if (!sci_uart_driver.state) {" code.
> 
> But actually, we can't.
> 
> The first driver to hit this code is supposed to load the
> sci_uart_driver.  We can't know if we are the last driver to stop using
> the sci_uart_driver so we can't know if we can free it.  This looks like
> a very ugly hack to me.  It should probably be using ref counters.
It seems something should be considered deeply.
> 
> regards,
> an carpenter
> 
> .
> 


      reply	other threads:[~2019-03-11 14:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-11  9:51 Mao Wenan
2019-03-11 12:46 ` Dan Carpenter
2019-03-11 14:29   ` maowenan [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=50cd311c-651c-5c82-a3f4-8b1faf20110b@huawei.com \
    --to=maowenan@huawei.com \
    --cc=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@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

all inboxes | Powered by JetHome®