Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6845668imb; Sat, 9 Mar 2019 07:56:17 -0800 (PST) X-Google-Smtp-Source: APXvYqy8pcymRDVJ3Jl3JYMfePWkfp9JJv4J17k9YI4uzbWewKszzQF+OjTljTlu24LLisx+u2Ki X-Received: by 2002:a63:2dc4:: with SMTP id t187mr424431pgt.327.1552146977384; Sat, 09 Mar 2019 07:56:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552146977; cv=none; d=google.com; s=arc-20160816; b=cgTGnfancSfWT7WuoPKX/ruy0nkOA51krRsQX0q7Vg05JD0CCrJojdNYH1seInFROe PIWnkzZGWIbTPrixS3S8ZXO3oHgiXB44ImewUTLBEJu4dmLZmMS9kr+P//eGqQ2MuD2V tJBzCyjK0QLocHz7F0TFOCHQTmKEp8W48gZSz02TaMYbYxsUeTVXtZbiUN0isR8pNw6N 39lgAURPURP/7z0W56C1K6RpVfGa0SWyvBwsTvZRGvDy3yqVUqg7438hJMZrQrbli902 zyLVwpKA0beIjgqNfk2i2elPgZS7bI2d0skFpXxpRnm3GLW5UFSm9nZ3Njp+eL7J+sGA msDw== 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=fDxE/HEDyJoD5tX+9P8Nq9NwskV+Yl6zaHGMjoV6/Yw=; b=UlRrkb9Xcxo8bsX2LefyNtAX5YiHfdpyMX7vyh5WyiGlZ48zwXQJjcS8w6XmzUExcZ MaBObJzdJhFsxgZA5ERGQJ8y8VnNEUMxjRnsLgm8Vc9IgHwVcM986IyurO4c2P4dmJlB 1fC+97jY9TbLPY/U5hcH60XvxTibZ0WSS9Y+fdg2sAGC7PtQMu+x9oDGNOdwo6DqvYF9 z7KLMEA/DaIGiC+UnFDL3tDt6z538LdgMrQEzKWp6aaMHvx1+oYc06tbe2UfzWFqgFz9 ww5C5GMo7WUtiql5WHIeYc/nDKaNd1ywue/1UKigmtEKkWd3kVSYEIas8i5xfY6xM5KX YGrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ineb8Wgb; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org ([209.132.180.67]) by mx.google.com with ESMTP id 206si722773pgb.323.2019.03.09.07.56.01; Sat, 09 Mar 2019 07:56:17 -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=@gmail.com header.s=20161025 header.b=ineb8Wgb; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726450AbfCIPTq (ORCPT + 99 others); Sat, 9 Mar 2019 10:19:46 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:38124 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbfCIPTq (ORCPT ); Sat, 9 Mar 2019 10:19:46 -0500 Received: by mail-lj1-f195.google.com with SMTP id 199so455510ljj.5; Sat, 09 Mar 2019 07:19:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fDxE/HEDyJoD5tX+9P8Nq9NwskV+Yl6zaHGMjoV6/Yw=; b=ineb8WgbsY1bRzUL6isp8eJf1wP8C25M/7IzzFe+V6sqsdUY9/ayWJmzq6WanZkFmn 0a7fFk/HoEHFkoVvbqLSX1KKi0yWkIeTTxIEic2BQ6iapxNg1sq5qP0rsu8Ux1YKRtXJ WzmOIt2u3Y5wgs04BaIRzu+goHoKFP6BUD+ZM2pilU1Lyq+Zai2UaTm3OdG2cuqCC8Ng R2+6MaSgmeED43GxcUXVzhlwU3b9tkdOF5y0MLK6uqGGkRg9TVQ4wbECPivu2I5Xosp2 nsIuxUB/ZofLy4eJS/LQynhiapD8gC2E2Igs95YcAqybu9Axuy8OgjRD+7dbKz4acttq eXcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fDxE/HEDyJoD5tX+9P8Nq9NwskV+Yl6zaHGMjoV6/Yw=; b=X1XLzkgBUGLb4bmmyjBvUyeOqk5wmXUQmTRvuK+BS/J1CnZMkfg65krMVa0lg09CCZ 9rFGUxyfxR+Pzwop3LPtcTQV2gMsnKp2W73EuBMwk3J2PEisgJYVNvs1xGbPUC7jzw9J WBR8Gl615Tml61Rps6WNNElBVj/spEiAAp4EB7vt3ijSpk2LBSonAanteicFv86NzZul OflzDxvk3X9SsSV+9EePXxh1xdLnPeyspckM33rvRKzsjRJp5pLQ/o5WxURLURcUn1rV nd+yxQoq1LCBhYYfmjA9zDYSc6FnfPIwjhZhqwnUWs09P/Hts5jztZAGQ4lnZKWHQydX rb5w== X-Gm-Message-State: APjAAAWgjFPT0I93OU20R/PsUEolmBob0E8Gf2PbFzN2SYJIyDar1pEM 2WI2vBF85E/84uz8bgmdckI= X-Received: by 2002:a2e:93ca:: with SMTP id p10mr2982844ljh.16.1552144783334; Sat, 09 Mar 2019 07:19:43 -0800 (PST) Received: from localhost (89-64-59-159.dynamic.chello.pl. [89.64.59.159]) by smtp.gmail.com with ESMTPSA id c26sm157122lfi.96.2019.03.09.07.19.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Mar 2019 07:19:42 -0800 (PST) Date: Sat, 9 Mar 2019 16:19:17 +0100 From: Tomasz Duszynski To: Kangjie Lu Cc: pakki001@umn.edu, Jonathan Cameron , 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: <20190309151916.GB7820@arch> References: <20190309045141.8015-1-kjlu@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190309045141.8015-1-kjlu@umn.edu> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > + 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 >