Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp882525pxk; Thu, 17 Sep 2020 20:14:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtEotsFK38S42P8jeKpQ2J8hf7MUSsnbDXFnMo7yXmWrq0As/q6Yv+BB7m+8xsdpM3yoEX X-Received: by 2002:aa7:c648:: with SMTP id z8mr36799987edr.239.1600398893164; Thu, 17 Sep 2020 20:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398893; cv=none; d=google.com; s=arc-20160816; b=RcICMzO8jAqgtfp/bJ/cjXguI1Fh+/efZmtrQwFaY9w6jjLrepVcARwdtEMBZUeo3n J/QpIgvCjWC16s0QyE0+auG4H06k6bDskkTn49Df1TOVRUyXcrYQpIPVmZDsQjaE8laE 8an5G3iEAXAyM5e69noibPyn7ylTYnMm6VopvbWKl6QDoXa02LrqudRukHipX1pVRAtG T92gf9WUxpmVnTf+nu/lOGXoss7YcLCgP7w61BPGubOBHvlGS42DR5fzBPZWgHqXtMtI qcZnJFQ2acy6QSCGFvROG5BG+Loac6zp8FPziPqdKlm8Efkz9tRIfBuC71xSEk2KZiM2 mrbA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Hi7lI1+Rnf//+sUypFxdWVzIAQSCg8q2UaIgkYOBqNk=; b=Fi7dudisTKlzLgtd5vpkSFl3FVeyJdrFMlslSL++uvvKD8vIQw5GF8gIWUT4qn/UpA dA/9BZIL/1aWCXQajA9QvfeXWWaRPlBEJ7rhboRto7LK5pNpdJTtnh1jDhZ2PLqFhSBz H3AHT/TxBRh1ZxUfNwNr5plmbKY56YTXDdqRj8W4gIr+ayY4uorKlME9H7hWnpPUazxg V/0gZPJjqSZBzd9rt0kDboVgx3biBFNlynr5/Oic12imB3kF5yPiQg25Vn7UpWUXud1L z9nlNcM7OlACup3t4YpP0g8TweW0VO+QUb627e5zr2EAscRq/IG5tQlG+KDOwa1jVmFb JLJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w2Dx+Kbj; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si1261924ejb.651.2020.09.17.20.14.29; Thu, 17 Sep 2020 20:14:53 -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=w2Dx+Kbj; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728303AbgIRDNa (ORCPT + 99 others); Thu, 17 Sep 2020 23:13:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:46696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726583AbgIRCB5 (ORCPT ); Thu, 17 Sep 2020 22:01:57 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B7B323119; Fri, 18 Sep 2020 02:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394517; bh=lB+iWkzrjWwT35sfwmRttopkYwQyjYYUw5+6Fd6KN2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w2Dx+Kbjv9fl66GSVLrws13WMpKIK4PgKmSt30vdrseKkwNI4Dxjg+dyRWvCkqCwW W7FfLxYe5obBoxj8CSO2AUSQ1KfKFD/auHjfke9SGNyxMajckq/M0c3q0GCCzD8ZOC 30Zt207lS+ptLwNSme9wZNfDKGJO1krg3YIL+4qU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lee Jones , Daniel Thompson , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 5.4 039/330] mfd: mfd-core: Protect against NULL call-back function pointer Date: Thu, 17 Sep 2020 21:56:19 -0400 Message-Id: <20200918020110.2063155-39-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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