public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Joel Granados <j.granados@samsung.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
	linux-kernel@vger.kernel.org,
	Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Subject: Re: [PATCH v1 1/3] parport: Use kasprintf() instead of fixed buffer formatting
Date: Mon, 4 Sep 2023 16:44:09 +0300	[thread overview]
Message-ID: <ZPXfKcaTW6TXR8rc@smile.fi.intel.com> (raw)
In-Reply-To: <20230904131145.tp4umorb3t25tmsq@localhost>

On Mon, Sep 04, 2023 at 03:11:45PM +0200, Joel Granados wrote:
> On Fri, Sep 01, 2023 at 04:42:48PM +0300, Andy Shevchenko wrote:

Thank you for the review, my answers below.

...

> > @@ -431,8 +424,7 @@ int parport_proc_register(struct parport *port)
> >  {
> >  	struct parport_sysctl_table *t;
> >  	char *tmp_dir_path;
> > -	size_t tmp_path_len, port_name_len;
> > -	int bytes_written, i, err = 0;
> > +	int i, err = 0;
> >  
> >  	t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
> >  	if (t == NULL)
> > @@ -446,35 +438,23 @@ int parport_proc_register(struct parport *port)
> For this function I would even go a step further and start with the two
> kasprintf calls so we can then free them in the reverse order. And then
> leave the rest as it is.

I'm not sure I see the big picture here. Can you draft what you are proposing
(showing only the lines that are important)?

> I attached an untested diff that applies on
> top of your changes to show you what I mean.

Ah, I see now, it's below. And how is it better?
(LoCs statistics seems to be the same, so...)

What is a downside in my opinion with your code is this line

	return 0; --> goto blablabla.

this makes code less maintainable.

OTOH we may do what you want, but it will take a bit more LoCs and honestly
I don't see the benefit of doing that as in both cases the variable used is
temporary. What may be the good solution here is to split the repetitive
code excerpt to the parameterized helper function. But this will be another
patch which you can build on top of this series, right?

...

> > diff --git a/include/linux/parport.h b/include/linux/parport.h
> > index 999eddd619b7..fff39bc30629 100644
> > --- a/include/linux/parport.h
> > +++ b/include/linux/parport.h
> > @@ -180,8 +180,6 @@ struct ieee1284_info {
> >  	struct semaphore irq;
> >  };
> >  
> > -#define PARPORT_NAME_MAX_LEN 15
> This variable protected against port->name not ending in '\0'. Anyone
> worried that kasprintf could be unbounded?

I'm lost here. kasprintf() guarantees the NUL-termination. Any other concerns?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-09-04 13:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230901134310eucas1p1d9be610c894d46f19bb6c12576aef94b@eucas1p1.samsung.com>
2023-09-01 13:42 ` [PATCH v1 1/3] parport: Use kasprintf() instead of fixed buffer formatting Andy Shevchenko
2023-09-01 13:42   ` [PATCH v1 2/3] parport: Use list_for_each() helper Andy Shevchenko
2023-09-01 13:42   ` [PATCH v1 3/3] parport: Drop unneeded NULL or 0 assignments Andy Shevchenko
2023-09-04 13:11   ` [PATCH v1 1/3] parport: Use kasprintf() instead of fixed buffer formatting Joel Granados
2023-09-04 13:44     ` Andy Shevchenko [this message]
2023-10-02 13:06   ` 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=ZPXfKcaTW6TXR8rc@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=j.granados@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=sudipm.mukherjee@gmail.com \
    /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