From patchwork Tue Sep 29 10:59:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 291257 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=ham 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 10F2FC4741F for ; Tue, 29 Sep 2020 11:03:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2E9B21941 for ; Tue, 29 Sep 2020 11:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377389; bh=oq4Ifd3K+fcOwKUUcipTw4Zh0R6ErPjG2I9+58wT2HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=C1FoukphhHjR5zoCcmiR3ni8Rd97IOO9wNbWSeO1Eq228IW/plQA1c+rZCv761+5g ZJ+2egBfOY9siAKCZmoHp8gcAH86E3AYwdGTzyC5BSpxFClfIMgdY07qR1GtYxPPCI jD3hD6ButCbXWPEfyHamR38jHUCGG1YEitr8EO0w= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728358AbgI2LDI (ORCPT ); Tue, 29 Sep 2020 07:03:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:38732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728314AbgI2LDH (ORCPT ); Tue, 29 Sep 2020 07:03:07 -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 5834E21734; Tue, 29 Sep 2020 11:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377386; bh=oq4Ifd3K+fcOwKUUcipTw4Zh0R6ErPjG2I9+58wT2HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q74779taBiO/m0tjN7oaLkGDKhlHfrSbQ9S8WRBYd+tIZyLawNDIbxpzsx2sO0v4e NS+ghvLlcFUGiHyqgpIvwvBIWtn/2wwVpjU8Uu6QiFyJfkKw1MV6f4wBs61XMa1ydu AcKzCynp8mtzjG0OkK9zppfU03kp4Cy8qh0pcrlU= 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 4.4 18/85] mfd: mfd-core: Protect against NULL call-back function pointer Date: Tue, 29 Sep 2020 12:59:45 +0200 Message-Id: <20200929105929.127851937@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105928.198942536@linuxfoundation.org> References: <20200929105928.198942536@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 215bb5eeb5acf..c57e375fad6ed 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c @@ -31,6 +31,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); @@ -48,6 +53,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);