Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6492852imb; Fri, 8 Mar 2019 20:52:25 -0800 (PST) X-Google-Smtp-Source: APXvYqyX3+LkOovy+WLFz+W0gMc8lQHdEx/pcT58Fykn4OcqbiOfGgcNtBv+PP4WkLqeO0KZKAfR X-Received: by 2002:a17:902:9688:: with SMTP id n8mr22296497plp.133.1552107145826; Fri, 08 Mar 2019 20:52:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552107145; cv=none; d=google.com; s=arc-20160816; b=v2aKuwWXcVE+o8cfwm8/yRQBhBoDkNS0waV6uiRzyHLUNa8efO8YL8ms4Ml65sc8Ou q7kI1eVSNpQXQ186xi6LmVBj72g0ptupfn6xL/bi5sIzxwQyjYYIRXQw7y6vH+ZehDTh xFod7oL1l7419dqm34bEif/b01DcgbHMycR/d9udw1JGJuD34OJGeEWVcj9J7fUOsEVj k6D1QisUpnpaDG4037NE6yl6e1RViYU91HaPMazX0zi9OY/fIZRZHAgWz4/xsADxkhLn lNOEcUq8qZ/ZrxesDL1p41dPmTpRj5J+5nexDLIIfAcV3dMtOR9C9BBvGG2KoreNIqow /KHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=KeNhd+E2bDF8zX/IZPB7tqFnEXniWINKXyUoEIyOmAk=; b=v4NQYIsU+9PecsQeStUkB20WbQ9Jj6ER9Z0H2vIVQSWpTkFZoJJQcWv9NNaN0IxgSg Raf2Kiprujj4sj+Aa/ZT0q/wBG+SX8rux8g1kavb+qqNKbsHyZ81W2lDhgJ5W8o4ZV4F T7EETG1ChiralUoCuFYshmqrmpPBHSY4xJ7NnsltzN9DOoLzpvrSx1+QLR9GbDPpmmG+ OZf2w14uNa79gUKvvjEB7JZn54CHTau7J0c1nqn20pASuezniBf7UsSVkVqkrCR6TzQ5 0OwBCertEZbb2Q7YWf8RU83lAzs7oUTq5gBr4NeGrOaUw4ZfgRsyk3y7MJ0C6ms/lmCv 8Jbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=gE2ITjOQ; 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=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e10si5860228pgo.404.2019.03.08.20.52.09; Fri, 08 Mar 2019 20:52:25 -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=@umn.edu header.s=google header.b=gE2ITjOQ; 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=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726484AbfCIEvu (ORCPT + 99 others); Fri, 8 Mar 2019 23:51:50 -0500 Received: from mta-p5.oit.umn.edu ([134.84.196.205]:49162 "EHLO mta-p5.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbfCIEvu (ORCPT ); Fri, 8 Mar 2019 23:51:50 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-p5.oit.umn.edu (Postfix) with ESMTP id 9A83BCF0 for ; Sat, 9 Mar 2019 04:51:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p5.oit.umn.edu ([127.0.0.1]) by localhost (mta-p5.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7Jpq37UoaYME 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-p5.oit.umn.edu (Postfix) with ESMTPS id 62C39CCC for ; Fri, 8 Mar 2019 22:51:48 -0600 (CST) Received: by mail-io1-f72.google.com with SMTP id l10so16969142iob.22 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=QjXl/GDyt1/sCkSN3auCOivA8nOXdLw4uruUvrJT64zLMLPV63OjZD3mS9GTKxVoxl k3eWQsyEOQ/qje2210ZSHWsdzwybew3lbndRPGKThOcaNvo9vBhEG1p6lVvkp9daE7yV hAk4Unln7+xNpozHeDoEiGCI0MD/C6BerpaXBC15GRN/H50hvSz0mdNI+Qcvb3ci+p/k oNiCzx0IkSe+lxrD7ltwpJu5+5x4JNpLbkE1BQDeRSdSqC21bZyZ0ccqNpMJvhPSh/JF EmntV3V3fyfsoyChx5wln78IA3joFqNBpN2ZFJk0W7WwJ2YIGHFgAJiJnBD9cgiFAyeJ CppQ== X-Gm-Message-State: APjAAAV2Hi6mqXgNAtJbWbdqk0PHd+x4fMKzBBMe96icevp0HyfRlRDe czq8qn09C1C6bk21BL9GBtRYAErUun1ctt/6ykaJ3C69pYhI6gnFMstoF5vxXD5lIMd3nn/mh9D 3u1ZjvA+5a7ABPEmYwJk9yYN3yiJU X-Received: by 2002:a24:56c2:: with SMTP id o185mr10086087itb.57.1552107107928; Fri, 08 Mar 2019 20:51:47 -0800 (PST) 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.17.1