Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3744058pxk; Tue, 29 Sep 2020 05:19:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2VzJPFbylPQSeKInKxXgA1FI6S5mwI5dvWbLu/aCC9WOrZuBvxIc2Txczqq9quTnRv4p7 X-Received: by 2002:aa7:db02:: with SMTP id t2mr2843574eds.95.1601381977211; Tue, 29 Sep 2020 05:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601381977; cv=none; d=google.com; s=arc-20160816; b=eLLups204IUdJqLI2KGGPWJMWoR9WNrSrnWJ/6ddh2vw0cn4XAHF0TWcEaH8E1J3QE 2Xc1AU4DCD7SPhG8oTMeMec2dME0HVVdxvKVxe8UZUOkZ7J+bbXScIFsUMhvLXpDYVPD W5LP8EXtWoZpxxd8qQUxzfC9hckciENeG1JNN3f4i3xHx/X/spADqUjvnJq8o0WSdenV qWjTRTstqqneN8KIa1TWgSQEsv5rdeJGjNwLmMupeNgPutbvv56AFVNuoT9JgqTL099I 6qqViD/rtUdXu0GzwGcB3zfnWRRdiatLQYREf6YqkRZ3Cgc7ikvscM2n2HOkBSz/zxjY hQuQ== 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=Hi7lI1+Rnf//+sUypFxdWVzIAQSCg8q2UaIgkYOBqNk=; b=CVI2eU7zWm9Rq/ypENDT0bJH6s4uGC/4rwM4k5fk4vFITG6ZuiF4AuHefY0XIeYRna obFs9YK2cxlUKzYYhxiAyK6UJm3Tt1G8C8/2ndyNYRBLYbwi8VDJVY3vmtRp+bWgekOu hzO66WAAwWABVXCI/k6g3HoYAi+OS6OtOmw+R8k8fiH0vgVUNNPD+Li4TtxmSEc38uvO FAxQAFUnMdtK2BJ6kZvFwZ4nAlcgGfH/77EyPFCyjoSi5g11Csrcb7c6FzqB1QWTsQHP 4SDpOIOE4KP10toc40hoFTHUlIM+eI9awNUl305PdMmRKbgocapdoz1hc4fJW09/m8Ue sDaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ui6ZrSQC; 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=fail (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 da1si2567715edb.102.2020.09.29.05.19.13; Tue, 29 Sep 2020 05:19:37 -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=@kernel.org header.s=default header.b=Ui6ZrSQC; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732189AbgI2MQU (ORCPT + 99 others); Tue, 29 Sep 2020 08:16:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:49816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730038AbgI2LhA (ORCPT ); Tue, 29 Sep 2020 07:37:00 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D65EB23AF8; Tue, 29 Sep 2020 11:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379153; bh=lB+iWkzrjWwT35sfwmRttopkYwQyjYYUw5+6Fd6KN2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ui6ZrSQC72qCZdaLbswcJz+MoDkt+bmWAKjbSs+AOkU0fTvr6ccRge2R/oqfTOcxD LDqprz2SCPTY0maM0LOhD9dh0/1BkS2dZhPRYlSy1Tp+W7hWvPSiDvVY4vJ937dCGF ytPOmjjtz0ugO65g/H1XxGaenF28mk8PXPHNUbz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lee Jones , Daniel Thompson , Mark Brown , Sasha Levin Subject: [PATCH 5.4 037/388] mfd: mfd-core: Protect against NULL call-back function pointer Date: Tue, 29 Sep 2020 12:56:08 +0200 Message-Id: <20200929110012.290065002@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@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: Lee Jones [ Upstream commit b195e101580db390f50b0d587b7f66f241d2bc88 ] If a child device calls mfd_cell_{en,dis}able() without an appropriate call-back being set, we are likely to encounter a panic. Avoid this by adding suitable checking. Signed-off-by: Lee Jones Reviewed-by: Daniel Thompson Reviewed-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/mfd/mfd-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index 23276a80e3b48..96d02b6f06fd8 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c @@ -28,6 +28,11 @@ int mfd_cell_enable(struct platform_device *pdev) const struct mfd_cell *cell = mfd_get_cell(pdev); int err = 0; + if (!cell->enable) { + dev_dbg(&pdev->dev, "No .enable() call-back registered\n"); + return 0; + } + /* only call enable hook if the cell wasn't previously enabled */ if (atomic_inc_return(cell->usage_count) == 1) err = cell->enable(pdev); @@ -45,6 +50,11 @@ int mfd_cell_disable(struct platform_device *pdev) const struct mfd_cell *cell = mfd_get_cell(pdev); int err = 0; + if (!cell->disable) { + dev_dbg(&pdev->dev, "No .disable() call-back registered\n"); + return 0; + } + /* only disable if no other clients are using it */ if (atomic_dec_return(cell->usage_count) == 0) err = cell->disable(pdev); -- 2.25.1