Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5778717imu; Mon, 26 Nov 2018 05:12:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xw+Fwyd2c1vx1R8iRGL16c9JNV3XR2l10GZfA42IvysOs05qkqpZMVLNOO10aaWyGAR1bx X-Received: by 2002:a62:4e83:: with SMTP id c125mr26187157pfb.101.1543237957429; Mon, 26 Nov 2018 05:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543237957; cv=none; d=google.com; s=arc-20160816; b=vbnbE5WuziMEoPk4pXNvrQkgr+FSP1Bvxgf5MIwiwoaM/YdDCs3Dp6tPL5kCi/Asop Do+VMwu/Jbotc2Navf5tGVUGSnaIzjCvPCrsrIyGVD4vyD/Tds6jiPP4lkV0T7m1dILa mWN90CbooNhI51OyM3ycnf566b8dbDC/3i9jKqN7fEnWzHcSx/lGVvSgl0jWotr+qozC i2V1zMpiTCoF9Pa054rWe2sbwYfHUwymHoGU2L1uymK/+J9qBf8eCy5qNCqjWjryyAlb HjG+bUlGyeUn27Nc9bolsPxErC/RVMOjSfXWmq4pDujQwKE2Pt6NZehTiPlk4TMCE4hQ IKkQ== 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; bh=gCKyJmciitb4CBom8YNe6JlRdfqnEqElYncXXLTOUrg=; b=xwPNEYLerDwqH0WC2+Go0QeL9IwBExkVuJMgn96eWoV0vHd05iYOTrMeKbRjGZ+Zs4 4tRcAEdXA1WcUXTiDUm05V71BpQG34LhF3mchs7nqglXsCI11DVaCEuqPOZ19Zp4k/hi cm3c4JetO6dW1smshT2DXy/eWXxB0jKV2YA/uqyw/zAdSPRXsLdEazOX77cjcxndB5D7 HhdQeWD9pXo9UCRDrOXCtyMmrOhjkJvk8tty3+Id+AArp7BNdoC+2BHR3vXotFal8Rvy Gb2IdJwi8j9tUXJjYJ0lHdlc5wm8kjXd94Xllak3ytNH1HH2b46/hq8OBHt07Ddqd5Ve gV7A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7-v6si271377plp.130.2018.11.26.05.12.11; Mon, 26 Nov 2018 05:12:37 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726468AbeK0AEv (ORCPT + 99 others); Mon, 26 Nov 2018 19:04:51 -0500 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:60679 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbeK0AEu (ORCPT ); Mon, 26 Nov 2018 19:04:50 -0500 Received: by mail.osadl.at (Postfix, from userid 1001) id 979A55C0F44; Mon, 26 Nov 2018 13:10:09 +0000 (UTC) Date: Mon, 26 Nov 2018 14:10:09 +0100 From: Nicholas Mc Guire To: Dan Carpenter Cc: Nicholas Mc Guire , 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: <20181126131009.GA19931@osadl.at> References: <1543225144-27468-1-git-send-email-hofrat@osadl.org> <20181126130032.GJ3088@unbuntlaptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181126130032.GJ3088@unbuntlaptop> User-Agent: Mutt/1.5.23 (2014-03-12) 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 04:00:32PM +0300, Dan Carpenter wrote: > 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? just a typo > > > 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. > My understanding was that CHECK: notes are not strict rules but those that may vary from case to case - anyway you solution sounds reasonable and in any case better than: if (!st->iio_attr[cnt].dev_attr.attr.name) which just looked bad to me. thx! hofrat