From patchwork Sat Mar 9 04:51:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Lu X-Patchwork-Id: 10845771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 380F41390 for ; Sat, 9 Mar 2019 04:59:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DE542FF35 for ; Sat, 9 Mar 2019 04:59:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ADF42FF7A; Sat, 9 Mar 2019 04:59:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87AC82FF35 for ; Sat, 9 Mar 2019 04:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726422AbfCIE7E (ORCPT ); Fri, 8 Mar 2019 23:59:04 -0500 Received: from mta-p8.oit.umn.edu ([134.84.196.208]:50034 "EHLO mta-p8.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbfCIE7E (ORCPT ); Fri, 8 Mar 2019 23:59:04 -0500 X-Greylist: delayed 434 seconds by postgrey-1.27 at vger.kernel.org; Fri, 08 Mar 2019 23:59:03 EST Received: from localhost (unknown [127.0.0.1]) by mta-p8.oit.umn.edu (Postfix) with ESMTP id 075B4C66 for ; Sat, 9 Mar 2019 04:51:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p8.oit.umn.edu ([127.0.0.1]) by localhost (mta-p8.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7uG-uXwaARog for ; Fri, 8 Mar 2019 22:51:48 -0600 (CST) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p8.oit.umn.edu (Postfix) with ESMTPS id CD5DBC52 for ; Fri, 8 Mar 2019 22:51:48 -0600 (CST) Received: by mail-io1-f72.google.com with SMTP id p17so16958387ios.8 for ; Fri, 08 Mar 2019 20:51:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=KeNhd+E2bDF8zX/IZPB7tqFnEXniWINKXyUoEIyOmAk=; b=gE2ITjOQpV6XyzLKNYiHc3mtkXOxRKKUDS30AcLbnVj3jc6o5h9RkKvfkcxauYrZsX cqdnatZTI5tiLpK+sAIMns2BHx/zz7LXqa+NsNNKOs9+gIO032r0ZR5db1tbzyLw+LBt k5uVZcyPjbHTjYiit6pnvxCsY4FgRXSrPefL+KPMMq+BVNLu7v6bLZNukDcHFAVWFJ7p HrkNcnuWhJ1yaNDxY2JdA/Kg9iSs0cksgKUAmTFvVUxdKIcsJY2pHNvGZ2mENTKqnff3 yv0BrjHuxGHvxQg9heXHAOmOiMM+odbdA4JUZVDeQLZ3d4e0R+sJgFxrplzG8Gteb2si cQ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KeNhd+E2bDF8zX/IZPB7tqFnEXniWINKXyUoEIyOmAk=; b=C0dvMN9L+7UrcNH4eDqPWa8hALIJEYz1l3Q303oCXDoBfyayfqAazVlY91oHR+zzqL MPvIlag5CfG9tdbQNCvwfScS7k09EZhbbzWjI52h+LXHgMSGTHbcUsbefniJyf4N1mOU sg5r+Lfp2bQgb+F2/xhE8T120Spyk4Z6F05+JiPVMbobaz+l+VYR+jY8opefqWSMrSQY Z8rJtsdE9/4pFXuM7K6XBz9KPd/K+rlZCkU20nYAMQvEkKUHwB9ugh+x6Q5BOVvZ8iDu JdM+9sUUo1ia49rqFPjIKpwBUngPeGHxaOdTmMiUFGXrmIUXflJqgFw4gklC554j+nz6 fTiQ== X-Gm-Message-State: APjAAAWyBWdzW1Yc2d+cwdo0Haukj7xXedVX6uyTd7nlIllC+QDCSF8e eCN20u8EQh/PBNJ0zY7MPR5k32PKJ8/3Ck1vikBrtlXCVG2v+0jh7Fgvb0FrElJnOhhCb++FzxL lvWUZvEySqyRZtC/WSp7jYjYW X-Received: by 2002:a24:56c2:: with SMTP id o185mr10086093itb.57.1552107107929; Fri, 08 Mar 2019 20:51:47 -0800 (PST) X-Google-Smtp-Source: APXvYqyeWKVIzpKibJh/vjJcpXYxKT6CUmQ2bYAxg+0H8/FVA8bEYatyXYRRHXMbqPI/DWmjK3ozLg== X-Received: by 2002:a24:56c2:: with SMTP id o185mr10086077itb.57.1552107107687; Fri, 08 Mar 2019 20:51:47 -0800 (PST) Received: from bee.dtc.umn.edu (cs-bee-u.cs.umn.edu. [128.101.106.63]) by smtp.gmail.com with ESMTPSA id v14sm3865118iol.61.2019.03.08.20.51.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Mar 2019 20:51:46 -0800 (PST) From: Kangjie Lu To: kjlu@umn.edu 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: [PATCH] iio: max9611: fix a NULL pointer dereference Date: Fri, 8 Mar 2019 22:51:40 -0600 Message-Id: <20190309045141.8015-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.1 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); + 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;