Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6940310imb; Sat, 9 Mar 2019 10:35:34 -0800 (PST) X-Google-Smtp-Source: APXvYqyu9kdbjaW62vOWhs3eTC4/2c7myDReczhEJ6MtlnOpQ/wMnsUBL0y8k/N5zQjRyKH3Ws0W X-Received: by 2002:a63:5702:: with SMTP id l2mr22829707pgb.2.1552156533943; Sat, 09 Mar 2019 10:35:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552156533; cv=none; d=google.com; s=arc-20160816; b=xgvcDNZ5ngymJCYhZo4kbjTxHxqLLTguHmd34Ur4VB0CRHjYXYeFIJenqPQ4gXY/li SMc+I6Xaw+NcZqO36Rb1KJTf/CewlYcCaQoUVZyX3myAMnIHwd0wZ9smyX0y890U+Wpo 3nCFD5dFsOZBdUBkfuvp/3d8eRVSG2ClWwIi73ucUx7JhUDvLhVQtHxHopGc6Aw1jCyX 0fU6RS3EsxD6ybRRHKiWLzHL/ODu+d1opJdgOWuCb1o3A6R/BUsJuysgJBM44BwE8uDJ u7+eWI6QUUd72LR/T/RCLHQXDz+4AmywDNbLrdQrcteVPbwPYdgnOitGLMWKkahUpjFm OUSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=jauwVO2nzsdbP7HCXlQHuR1B9Wnp9C1twLUTHpUuAWw=; b=qPaC0tEYewNpRiO1OI5Cx6a3QuaQXP+1WVGL6pEB7X/J/wVjFa+1fwEexFJ9Z3XhpO dq79Phs6TE92IMmuxxirngzDWuzs67K9uZ0IuUy49eqf3H+z+4i3RxRrsv+IFjNLE8/K GIxsrbkvWcH7M4RBP/5UiG5SzwHSwdhIW/8kJpD+gg0IhJu7gXnX1m67K9vabA1MV7jf +FGtT3MTLdFhOuEuIrPgz6dyXzuGKWhDw3LHGUU+VV+0n2NFlxnoenFKUIyY16HakMfz 8LT8LAgXwtWEbGCljWoUJbtB6iXrVwApR4OH+hU9QiJ2Pv8D9jUsIyKokjgiYvHhn19e qjNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ef8CqWZN; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si985179pgk.202.2019.03.09.10.35.18; Sat, 09 Mar 2019 10:35:33 -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=@kernel.org header.s=default header.b=Ef8CqWZN; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbfCISeo (ORCPT + 99 others); Sat, 9 Mar 2019 13:34:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:50976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbfCISeo (ORCPT ); Sat, 9 Mar 2019 13:34:44 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A8F3207E0; Sat, 9 Mar 2019 18:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552156483; bh=flmMOEoEdSmSBfc7ltQFCjwpzDC1bz5Oi6wc1NnW0i8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ef8CqWZNrYs7uxoff89lnsMQrpfurEyteZqYsCqPUIpjH2kjzfc1wwG7ndZtGKToh 23p+alM7FZZKvXuXOYNPWTuu8/P5kRRvp4D8kXxhHOZOhjRDyT/gDVLq9YZuJIMRjy 9LInmNB74ivy96meOC2lhl2u9SB6cEdpoIJEhNI0= Date: Sat, 9 Mar 2019 18:34:37 +0000 From: Jonathan Cameron To: Tomasz Duszynski Cc: Kangjie Lu , pakki001@umn.edu, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Stefan Agner , Kuninori Morimoto , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: max9611: fix a NULL pointer dereference Message-ID: <20190309183437.479f90a1@archlinux> In-Reply-To: <20190309151916.GB7820@arch> References: <20190309045141.8015-1-kjlu@umn.edu> <20190309151916.GB7820@arch> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 9 Mar 2019 16:19:17 +0100 Tomasz Duszynski wrote: > On Fri, Mar 08, 2019 at 10:51:40PM -0600, Kangjie Lu wrote: > > of_match_device may return NULL when it fails, and in this case, > > there will be a NULL pointer dereference. The fix returns > > EINVAL when of_match_device returns NULL. > > > > Signed-off-by: Kangjie Lu > > --- > > drivers/iio/adc/max9611.c | 7 +++++-- > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c > > index 917223d5ff5b..531b6614ea29 100644 > > --- a/drivers/iio/adc/max9611.c > > +++ b/drivers/iio/adc/max9611.c > > @@ -524,13 +524,16 @@ static int max9611_probe(struct i2c_client *client, > > { > > const char * const shunt_res_prop = "shunt-resistor-micro-ohms"; > > const struct device_node *of_node = client->dev.of_node; > > - const struct of_device_id *of_id = > > - of_match_device(max9611_of_table, &client->dev); > > Given we got to this point how this can go wrong? If this is to squash a warning then there may be some argument even though it can't actually fail. If there is such a warning please put it in the patch description. Thanks, Jonathan > > > + const struct of_device_id *of_id; > > struct max9611_dev *max9611; > > struct iio_dev *indio_dev; > > unsigned int of_shunt; > > int ret; > > > > + of_id = of_match_device(max9611_of_table, &client->dev); > > + if (!of_id) > > + return -EINVAL; > > + > > indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*max9611)); > > if (!indio_dev) > > return -ENOMEM; > > -- > > 2.17.1 > >