From patchwork Tue Sep 29 10:56:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 290894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11623C4727F for ; Tue, 29 Sep 2020 12:16:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4B322075A for ; Tue, 29 Sep 2020 12:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601381809; bh=lB+iWkzrjWwT35sfwmRttopkYwQyjYYUw5+6Fd6KN2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2Y6gb5tz0S6UG72varuz8EbpH06uC9RKl2edv62AU2OakbFUCogJf0ir4+z1hi+5X yh+83jsWrIeSytv47hC+AT/o5RNTCs4rVoyzK3n7lF/lpSb7Ywaar6Zt75PXA76+dD paGsrAosWpb14kZXF3WsrhZi2fqkez4+4JLvyglg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732251AbgI2MQK (ORCPT ); Tue, 29 Sep 2020 08:16:10 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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);