Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp136316pxj; Thu, 3 Jun 2021 02:54:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySyM7X2XsMFwHLf+jesreJ+WulxKfJy/L28FgJKKNB8tyvFaDJhlxklyW8MbIrOlQJOZQf X-Received: by 2002:a05:6402:35d4:: with SMTP id z20mr42913532edc.164.1622714052230; Thu, 03 Jun 2021 02:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622714052; cv=none; d=google.com; s=arc-20160816; b=QUVc/+teHNd9gZ8W1GDAL4tQkyBTXsnD+beuFMoWpBrda0mYod9dTpaRp3317CKIz/ 2OQl94oE9R8Pq3MNvZzkSIQCaG+RQi34Mk9yrDFqqCAL0lJfu1sHh/KPopZ87nj+WSj4 kPSrqx/dIKN+aX6AahHnZynKPnoTbfu0TmqREDYmNycToiuCgWzWfTR131gCZ//gDBRt yI5YyhLmeDi9Mwm1R6fKE84unH9LVOLv6/jGJrKtJ3eGI2U4egrEKvMAlXE/Pkm5Z/Fk +E1ARvQnZHD1C5yeQMgHuI/is84v/UJCMt0eMz0RtnfhE1ys4rQPa0M4ZayTFwumMMU8 Q/dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=k94usgXa6GClLbJt1Mq5SUGlAvC85kxew1BESlY3ZIQ=; b=YZr5k6YXN+vGB7rKLqjvq2BVec9N86H0WHFxF8ppvSBa4mMhhkn+Ks9KCT66hLwRsG p7tlRl71XotuctY9i8FxBNAMHew3D/2oGjVFN7PN50vHxpPj45WJPVJCHD8JQY03WjPy efI2+aScPU7ySbdd6L+XcwXNdVF+Lvv8CpCEI0K2VvYYPRpFTvO98bXrUVquO1w5oE2o sIvqOv5Y2lk/lrZVIuW5d/gj7Xb2u+enjs50jIjxY6Cdzawymr9TDqDMP2D3a36ht78b WZhZ37eCNrgXE+8cX7Rj7FhDGz/ID99P4mn2az9zsrNCVqW6Mn4fztAd5JSsVV/O64Tj 9UjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=aM1D5Tlt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si2265345ejd.643.2021.06.03.02.53.49; Thu, 03 Jun 2021 02:54:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=aM1D5Tlt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229753AbhFCJxB (ORCPT + 99 others); Thu, 3 Jun 2021 05:53:01 -0400 Received: from mail-pg1-f174.google.com ([209.85.215.174]:37735 "EHLO mail-pg1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbhFCJxA (ORCPT ); Thu, 3 Jun 2021 05:53:00 -0400 Received: by mail-pg1-f174.google.com with SMTP id t9so4720429pgn.4 for ; Thu, 03 Jun 2021 02:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ingics-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=k94usgXa6GClLbJt1Mq5SUGlAvC85kxew1BESlY3ZIQ=; b=aM1D5TltwyXFGp+goF4UEPmGGv4wTw3PVJuLDCUfEM3Hk5wgN/fwQteO/x4toI/APg 0hmYNMaH8Xo1k5YqPcguJgaeq2tHs7JUqRRuGH025fiV8nmlhg4kdQcCwhKh5ZBgJm+u anU2uYwT73pUni596NIi2UDz6WX7nlr+/GfprkJfqgw8Q9ITJL3C4aK7nlJ/Hk5Q8tLP GyOnpwJiy2dhnNS1cyUPuU2RzK0NfODsZb50qS/9gshq/0rOwMOLyi895uLVVkimemjL OMFDkjPzLD3u93QFnco/kxvLx9WOIiZGc/T4bTHuSvoFlKF7lJGo32On3cFtPdvxY0B/ XyAg== 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:mime-version :content-transfer-encoding; bh=k94usgXa6GClLbJt1Mq5SUGlAvC85kxew1BESlY3ZIQ=; b=aI/5FewcQGBpzsiOyU2nhj4KwmulMlNMhrO5dBYDsCNncbHcQJyfyaZd3FAC32tyyR 0iOboo/KB80l9tGvFbXLTDmwqw8la3pZkPi9HS8VdK/71ZEY0v5XuR0QJMJLKd46RpBD FXGhjR0dGinUbnuogxD0B6wDAP2GagsFcEYshQw35kylQX4octqvFskfHdw4q5nE/jaG ga9kkLCQ/jDL3J94mpJsUTLsqo5KXqgOZx7aSFIqDIUscNJm6XH8GAZqyiBE8gJ1zIze iHoBZprSIG4IHfwI9/GdMn9QOkxZW8oEZSS/YslkUNRx3rWa7eoI10cgDOR41UdB5Ifk JlmQ== X-Gm-Message-State: AOAM533jN1aQce+NxfB3NZ3G8WnXt1/lu0jJS7uZKPDNtBQjXPktuS/7 6iPX6siWH7U+8swjGuLF5lVvDVQnGsKv3il8 X-Received: by 2002:a63:ba18:: with SMTP id k24mr6163796pgf.65.1622713804165; Thu, 03 Jun 2021 02:50:04 -0700 (PDT) Received: from localhost.localdomain (122-117-179-2.HINET-IP.hinet.net. [122.117.179.2]) by smtp.gmail.com with ESMTPSA id b20sm2055194pgm.30.2021.06.03.02.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 02:50:03 -0700 (PDT) From: Axel Lin To: Mark Brown Cc: ChiYuan Huang , Liam Girdwood , linux-kernel@vger.kernel.org, Axel Lin Subject: [PATCH] regulator: rt4801: Fix NULL pointer dereference if priv->enable_gpios is NULL Date: Thu, 3 Jun 2021 17:49:44 +0800 Message-Id: <20210603094944.1114156-1-axel.lin@ingics.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org devm_gpiod_get_array_optional may return NULL if no GPIO was assigned. Signed-off-by: Axel Lin --- drivers/regulator/rt4801-regulator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt4801-regulator.c index 2055a9cb13ba..7a87788d3f09 100644 --- a/drivers/regulator/rt4801-regulator.c +++ b/drivers/regulator/rt4801-regulator.c @@ -66,7 +66,7 @@ static int rt4801_enable(struct regulator_dev *rdev) struct gpio_descs *gpios = priv->enable_gpios; int id = rdev_get_id(rdev), ret; - if (gpios->ndescs <= id) { + if (!gpios || gpios->ndescs <= id) { dev_warn(&rdev->dev, "no dedicated gpio can control\n"); goto bypass_gpio; } @@ -88,7 +88,7 @@ static int rt4801_disable(struct regulator_dev *rdev) struct gpio_descs *gpios = priv->enable_gpios; int id = rdev_get_id(rdev); - if (gpios->ndescs <= id) { + if (!gpios || gpios->ndescs <= id) { dev_warn(&rdev->dev, "no dedicated gpio can control\n"); goto bypass_gpio; } -- 2.25.1