lkml.org 
[lkml]   [2018]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] staging: iio: adc: ad7280a: check for devm_kasprint() failure
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

\
 
 \ /
  Last update: 2018-11-26 14:01    [W:0.073 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site