Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3951962ybg; Fri, 25 Oct 2019 11:11:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZEwxeCEtdstZQcCUTD5nWiD+Ai6jq2IuZLJEbKjJZciScOup8WiFMtfcsh+skgv4TaQ4V X-Received: by 2002:a17:906:1d59:: with SMTP id o25mr4832474ejh.115.1572027094891; Fri, 25 Oct 2019 11:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572027094; cv=none; d=google.com; s=arc-20160816; b=YF6j8eJLqCUk6glEFJ6UneLl82fwn+7tIdJv9DCjRHjwyTSufx1M8daPFGdSOdDwOU ilNwj0f0K69w1E2m6wWY77wZYi7Gwg1nUbUD82+5oS0Zd4Ng+90pk/brAfy5ExMW3c1F Kx/hkCoNH4LWEeShnka5qTrIbt5F4ETtLvxjifiKLADumQQk/lxJpTs0Cdm6ZHeJBe/5 UYaoR02YXgZ0lfyhTWZzR+rhr3tfi6ciWgIYx12v+lyT8Mhk6gnXW5TI0zq5xEOmmBlB 4Bf5QCi/n/ANBu/Btiiy0719Wgm4aUDIkSeuuf4Otlo9J4TvgzW2wN8b3VkkQAbrHdhP BPsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=+Uje5yZA2ldJsbsoiBPp+JyZjTmn5fr8PAwcjGY2GnI=; b=TbjO1o6BZfa8u27QaeqNa0CpG7qDeXllsup1Vl4OlbAlBhFB2OmynpYP+GVIKgTq0B 4grfJIqhcvnN+t5Ni64n/vLlizG7Cx9vwtDSpDniS10a3oARJCXjSQYmL8mjN+/rAQFq Nm0L3c6VzRlexS71Qfhz3GHbmU07gxLC4lwiI2cAas4ItrdLPSPGyk+qrcMUX7OCHYrs Ye0n7i608zrFsFJhxGMKi4+qYtvDzQYs0tZkvQCDWLuzjqgH5FikH0XwKoBjt62Mc345 6nDmmkiYKXzLk18uGKHsWzs5ePDThLtbuBfFmsgovNnXqqVePPxyJDf8hLL/GVXyoBT6 JwVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DQl9V900; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si1764573ejb.54.2019.10.25.11.11.10; Fri, 25 Oct 2019 11:11:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DQl9V900; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503581AbfJXQiw (ORCPT + 99 others); Thu, 24 Oct 2019 12:38:52 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38680 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503545AbfJXQir (ORCPT ); Thu, 24 Oct 2019 12:38:47 -0400 Received: by mail-wm1-f65.google.com with SMTP id 3so3254029wmi.3 for ; Thu, 24 Oct 2019 09:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+Uje5yZA2ldJsbsoiBPp+JyZjTmn5fr8PAwcjGY2GnI=; b=DQl9V900fqGUpTL6GCaKfkeZ3gpfIHFqAKSX3ufvAjrIcUCC99G8QrABRgrFAHr84f zXLGkBQbvxYo558DCuJqQRDDXaj2qphtEatUBS+Lk2L/kgUEZOlNLKkQr/2VGOUirh4E 6jKdZxmOXPYIkjq+XUBdV+4Kw/ot1PyjPtVGHPHjzWvr5e5pNz9JmDdPSIPFVB09IPWO J99BmaTltlCpMUovCATgjqDRfUheM9tsvnCGce4Ysz+isq5zOjxTekh7k4kElKxW1h0I wSMBV1bRCLq9eaApiDlolzZZeA1p6It53pyezLs2vAm0LSkxnBL7yVJGV/ov+1Xf6Njw Chtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+Uje5yZA2ldJsbsoiBPp+JyZjTmn5fr8PAwcjGY2GnI=; b=gjkuulNg03UzZMx//iRvHYESdwVaMwsNbQZOPbY2gEnU0WbO8dsF4g8zxv68kCkTsk 8gSLOlpdXzRolJ0Ppt5YPyq4LTveev3IWBbQuwmmbIZmmf9XdB8BAkYWo1WZaqsVycn1 RZU9/vKUOVkNkjdhPcL9R2m4NTz3XJg7xQzC/zdNtgAOV2rHvSVMTaIgGKWNrZePtPYY LQ/hp055GVNLfM1XbkVpCeJWCR47RbA0F2sd4zcoaK4bCjPCYR5exIxpHJf6i5sSzJbJ II5pGn4xr4MkagZ3faum7aL+5CNwYmaIOcvrJBlbeQSZu6tdgUgxD+B0R7WtyCdeQkFu EeEg== X-Gm-Message-State: APjAAAXyJnJ7YNLBQ67SFlqydtQK3TeqKrFP6j3iqSyEhC96f60diIdb ufeD+u4XvL4l6IMLFZ3BiHTXUB3h8b8= X-Received: by 2002:a05:600c:143:: with SMTP id w3mr786098wmm.132.1571935124805; Thu, 24 Oct 2019 09:38:44 -0700 (PDT) Received: from localhost.localdomain ([95.149.164.99]) by smtp.gmail.com with ESMTPSA id 6sm3446175wmd.36.2019.10.24.09.38.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 09:38:44 -0700 (PDT) From: Lee Jones To: daniel.thompson@linaro.org, arnd@arndb.de, broonie@kernel.org, linus.walleij@linaro.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, baohua@kernel.org, stephan@gerhold.net, Lee Jones Subject: [PATCH v3 08/10] mfd: mfd-core: Protect against NULL call-back function pointer Date: Thu, 24 Oct 2019 17:38:30 +0100 Message-Id: <20191024163832.31326-9-lee.jones@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191024163832.31326-1-lee.jones@linaro.org> References: <20191024163832.31326-1-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 8126665bb2d8..e38e411ca775 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.17.1