Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3938324pxj; Mon, 21 Jun 2021 09:46:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyl2R2m19uivs5h4Ys5X+7t4rUwEu96SPtPEClvcadxO6gLPsIZw+kVBV7w17kB5Mgp04H X-Received: by 2002:a05:6602:1810:: with SMTP id t16mr20280561ioh.48.1624294006937; Mon, 21 Jun 2021 09:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294006; cv=none; d=google.com; s=arc-20160816; b=pr6Eic69Fa5sbATGY5kpc4HL9D99R6I4wutUd84qHVf8QbjE3GSaNc0WBWTUwrzqGj j5HRJLEDuXAQbOUxJbxlDCaZ0CGX48xP61lGhZ87PbDy0O1ce5r9XHfUhR4uQVSeYddK emhmm3XMaUUj0N48QgvtEQkDArCumdlAHuA6jN8H1tjHtrkYqqgAcPOjOxfjSFUekOxP 57qNmVTewF1x0lnj1UoW/zRBqjNn47Gq01sWzterA6PmoUd/DCxWbwNV267TOpdIHzSO swROzC4gfrstm04wf/tCUI11cX5oKq+GZvCzo5p02OiVRqvaHjCgCAB2vga4uMoJcVGr t2/w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e4+uwu90SmMLaohXdIMOOwwMqEYjsK0cjwQvziXRUDI=; b=UV4MyotFFfctJWPV7oCWw81JdEkow63A+VOPQW+Gvv10JllQZnDZLpH6FVwa44n1ln XuGPaR6oJbXhg0mPD2nWPsKiI0R3f23DuI655r3Ki2Brw3JtYv6JvWuYPeAQp9QKyF+L GLWrOrmAwCCbAI1lRqZVjr5zfpBqP3x06Fa6UDFf4ZYqJg5fWTtfles+kF5hfK/EROIT Y9STeyfJ+BxCxgCsGxuw6rrUE+vnqLq7GUQOW721Z/NpusfgB4sqY6AwfJg42C+vvtp/ TNaYFSJVuNRBSDFXnFINeqq6PNMVCnb3kM33XnqZVo6/XpfpRtbbFrydF96eRRb+R/9D 3DpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A9b67TdK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si16443595ioq.19.2021.06.21.09.46.34; Mon, 21 Jun 2021 09:46:46 -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=@linuxfoundation.org header.s=korg header.b=A9b67TdK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232813AbhFUQsP (ORCPT + 99 others); Mon, 21 Jun 2021 12:48:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:33922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbhFUQnn (ORCPT ); Mon, 21 Jun 2021 12:43:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 07EF861380; Mon, 21 Jun 2021 16:31:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293108; bh=3LWTFrPqZrRejivSLKDXE5jWosmTTHgrAR+hU/+DOrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A9b67TdKZTu+9EZrZPV1DRM0Kh5q6O7n0MXQQFURLwmIh2ZwTxMOrrtNJiBARLoeD nzUGYeTNxysyYhmfg7sbLB69JIFlpHIyYeVRAjh9Jl0FhPROs8HkAYMAzMLBlyZULp D1m1dPaFsijDIxuvU5NJtrxFLNTGFb4CMeiOXtJc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Axel Lin , Mark Brown , Sasha Levin Subject: [PATCH 5.12 102/178] regulator: rt4801: Fix NULL pointer dereference if priv->enable_gpios is NULL Date: Mon, 21 Jun 2021 18:15:16 +0200 Message-Id: <20210621154926.257098564@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Axel Lin [ Upstream commit cb2381cbecb81a8893b2d1e1af29bc2e5531df27 ] devm_gpiod_get_array_optional may return NULL if no GPIO was assigned. Signed-off-by: Axel Lin Link: https://lore.kernel.org/r/20210603094944.1114156-1-axel.lin@ingics.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- 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.30.2