mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Nicholas Mc Guire <hofrat@osadl.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	devel@driverdev.osuosl.org,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	linux-iio@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH] staging: iio: adc: ad7280a: check for devm_kasprint() failure
Date: Mon, 26 Nov 2018 16:00:32 +0300	[thread overview]
Message-ID: <20181126130032.GJ3088@unbuntlaptop> (raw)
In-Reply-To: <1543225144-27468-1-git-send-email-hofrat@osadl.org>

On Mon, Nov 26, 2018 at 10:39:04AM +0100, Nicholas Mc Guire wrote:
> devm_kasprintf() may return NULL on failure of internal allocation thus
> the assignments to  attr.name  are not safe if not checked. On error
> ad7280_attr_init() returns a negative return so -ENOMEM should be
> OK here (passed on as return value of the probe function).
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> Fixes: 2051f25d2a26 ("iio: adc: New driver for AD7280A Lithium Ion Battery Monitoring System2")
> ---
> 
> Problem located with an experimental coccinelle script
> 
> As using   if(!st->iio_attr[cnt].dev_attr.attr.name)  seamed quite
> unreadable in this case the  (var  == NULL)  variant was used. Not
                                   ^^
Why two spaces?

> sure if there are objections against this (checkpatch.pl issues
> a CHECK on this).
> 

You should just follow checkpatch rules here.  If you don't, someone
else will just send a patch to make it checkpatch compliant.  One thing
you could do is at the start of the loop do:

	struct iio_dev_attr *attr = &st->iio_attr[cnt];

Then it becomes:

	if (!attr->dev_attr.attr.name)

It's slightly more readable that way.  Keep in mind that we increment
cnt++ in the middle of the loop so you'll have to update attr as well.

regards,
dan carpenter


  reply	other threads:[~2018-11-26 13:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26  9:39 Nicholas Mc Guire
2018-11-26 13:00 ` Dan Carpenter [this message]
2018-11-26 13:10   ` Nicholas Mc Guire
2018-11-26 13:26     ` Dan Carpenter
2018-11-26 16:56       ` Joe Perches

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=20181126130032.GJ3088@unbuntlaptop \
    --to=dan.carpenter@oracle.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hofrat@osadl.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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®