Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5763303imu; Mon, 26 Nov 2018 05:02:34 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wy7ADhJtrDgudUBKUOvSaDPFMp8kNw0+CNtIuhIT9Km1VBoQ8pxxTFx6jSTmSc/d37b6PE X-Received: by 2002:a63:5f95:: with SMTP id t143mr25070912pgb.395.1543237354573; Mon, 26 Nov 2018 05:02:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543237354; cv=none; d=google.com; s=arc-20160816; b=gJRUXwALIYyVx0PSXJWPGZMl9iKRKskUqy8OT55zMXzXcestrrYA1xwo1YJYpNk9Qq 2XetML22wUwGeyurjSt8jntvjCM2cIJrDOmFPRJwrOylzjQ9mvNhISmhO7zIv2685hcc U1YJM8T+JPwvxyEfv7zXidlxZOrJToW6agbvLEP9uoyI/zmTz54uTMHzFExXfRfWU4PF mIh43EXaO36D8wy6WnaCmONn6oW34rMf8LV9hzE7rpheVUjOw/8J2k9e82xOMjD3UVZ0 d1icbvFsu9o1f+Z9m+0ZtfCz+/qEX6qkNR/2f+nHTTWsi585xeabtOZGdAXE/mD8GkcR uUwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ice7oyEmjHoCDXbmjBAOLFr2/xqsCdYgmiQZPiRWBM0=; b=ECSCPWH8ejmnJhvApfxtupj1Um2xuznENpziZtHAA91b9R8j8uYxi0EH69IdkA23DW r4FoLREML1hk9gUMchti3LH2eUINmT2dE5hUZPCWYRs80yIonrVGhW1lZd2PdaD/f48g RAaGd9+sVltB6FHou76gyV7Qf832Urmoq/V4/RnwHPlbPKU7A7el0sxqmlp/0voc/d8v cGzvV5QXJscPZ9GCz+/tv3+6xkkg6oCAuNz+uvVgJ9sIaiId4or/VYLp64VeJSV/+cnN sS+rLlpNHpC1HFaLCBjCK9BrFYwLR9/vxcHc4YEFBOq+sJFDjeXLzVL5nScQSBsM5JvO FZyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=gnryV7RV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r196si223200pgr.311.2018.11.26.05.02.10; Mon, 26 Nov 2018 05:02:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=gnryV7RV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbeKZXzd (ORCPT + 99 others); Mon, 26 Nov 2018 18:55:33 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:41356 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeKZXzc (ORCPT ); Mon, 26 Nov 2018 18:55:32 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAQCiARk105983; Mon, 26 Nov 2018 13:00:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=ice7oyEmjHoCDXbmjBAOLFr2/xqsCdYgmiQZPiRWBM0=; b=gnryV7RVSn3DN/RXy/45F8w6nqcgO5srNPC5XGCuQAqMbN0VEQRwWij8lVtSB6gZoIYO 6S0wXfVE0u0Me8GtQy3+CadUmOQr/ifBYZbaUdPcSTP+6NgGRPjQ7V5kXnaKtiWEXg7W jcRAHvm0m/4CObvFZ6MYvQsk13PY2WGxf2Owz8KMwfsPEcKqIugSshNaRAl44W6OS6Hy HEsDFg5qjB66VnBrhKfwiePsPbcO3JPZBCQRG2GlRf2I8xF4zN8bmN2huEOKw+knrykz dyf67SZogIXp6AxIk0ILKHEWJSAoXQLQ9ChqNnN+0yyRQwzKFU+sCgg8i3DeH9WuZ47Y dw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2nxxkq5hfn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Nov 2018 13:00:48 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wAQD0kBs026567 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Nov 2018 13:00:46 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wAQD0inH008016; Mon, 26 Nov 2018 13:00:44 GMT Received: from unbuntlaptop (/41.202.241.51) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 26 Nov 2018 05:00:43 -0800 Date: Mon, 26 Nov 2018 16:00:32 +0300 From: Dan Carpenter To: Nicholas Mc Guire Cc: Lars-Peter Clausen , devel@driverdev.osuosl.org, Michael Hennerich , linux-iio@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Peter Meerwald-Stadler , Hartmut Knaack , Jonathan Cameron Subject: Re: [PATCH] staging: iio: adc: ad7280a: check for devm_kasprint() failure Message-ID: <20181126130032.GJ3088@unbuntlaptop> References: <1543225144-27468-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1543225144-27468-1-git-send-email-hofrat@osadl.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9088 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=701 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811260118 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 > 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