From: Arnaud POULIQUEN <arnaud.pouliquen@foss.st.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
<linux-kernel@vger.kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Subject: Re: [PATCH v1 1/5] tty: rpmsg: Assign returned id to a local variable
Date: Tue, 2 Nov 2021 14:19:06 +0100 [thread overview]
Message-ID: <ef2cca2f-8566-ad3c-3ab2-cf0a4439faa0@foss.st.com> (raw)
In-Reply-To: <20211025135148.53944-1-andriy.shevchenko@linux.intel.com>
Hi Andy,
On 10/25/21 3:51 PM, Andy Shevchenko wrote:
> Instead of putting garbage in the data structure, assign allocated id
> or an error code to a temporary variable. This makes code cleaner.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/tty/rpmsg_tty.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tty/rpmsg_tty.c b/drivers/tty/rpmsg_tty.c
> index 813076341ffd..8c17ddbf371d 100644
> --- a/drivers/tty/rpmsg_tty.c
> +++ b/drivers/tty/rpmsg_tty.c
> @@ -121,15 +121,16 @@ static struct rpmsg_tty_port *rpmsg_tty_alloc_cport(void)
> return ERR_PTR(-ENOMEM);
>
> mutex_lock(&idr_lock);
> - cport->id = idr_alloc(&tty_idr, cport, 0, MAX_TTY_RPMSG, GFP_KERNEL);
> + err = idr_alloc(&tty_idr, cport, 0, MAX_TTY_RPMSG, GFP_KERNEL);
> mutex_unlock(&idr_lock);
>
> - if (cport->id < 0) {
> - err = cport->id;
> + if (err < 0) {
> kfree(cport);
> return ERR_PTR(err);
> }
>
> + cport->id = err;
Set the cport->id to the err variable on success doesn't seem completely clean
to me either.
What about renaming "err" by "id" as done in [1]?
[1]
https://elixir.bootlin.com/linux/latest/source/drivers/tty/serial/mps2-uart.c#L526
Regards,
Arnaud
> +
> return cport;
> }
>
>
next prev parent reply other threads:[~2021-11-02 13:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-25 13:51 [PATCH v1 1/5] tty: rpmsg: Assign returned id to a local variable Andy Shevchenko
2021-10-25 13:51 ` [PATCH v1 2/5] tty: rpmsg: Unify variable used to keep an error code Andy Shevchenko
2021-10-25 13:51 ` [PATCH v1 3/5] tty: rpmsg: Use dev_err_probe() in ->probe() Andy Shevchenko
2021-10-25 13:51 ` [PATCH v1 4/5] tty: rpmsg: Add pr_fmt() to prefix messages Andy Shevchenko
2021-10-25 13:51 ` [PATCH v1 5/5] tty: rpmsg: Define tty name via constant string literal Andy Shevchenko
2021-11-02 13:19 ` Arnaud POULIQUEN [this message]
2021-11-02 14:40 ` [PATCH v1 1/5] tty: rpmsg: Assign returned id to a local variable Andy Shevchenko
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=ef2cca2f-8566-ad3c-3ab2-cf0a4439faa0@foss.st.com \
--to=arnaud.pouliquen@foss.st.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).