From patchwork Thu Oct 24 16:38:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 177546 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp2400292ocf; Thu, 24 Oct 2019 09:39:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjkD75X+uqlRn37Kga2XH0P1lqQjwJkL8QpSdatX0tvDdIoHezBkiFB080t7oZhbLh3Y+O X-Received: by 2002:aa7:cb5a:: with SMTP id w26mr44673578edt.188.1571935141178; Thu, 24 Oct 2019 09:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571935141; cv=none; d=google.com; s=arc-20160816; b=aNkRy1yC71f2sWuYZ8QaTTzvsVnrQsR/WXYksRZQ/FQRCIvWc5IhNlL+Ut9AxGSRqP rmdmEtelW4hRWpeQcrw+Mgyz/TUYEi7jD0sNUc1VcJS3DZrxhnyLY82JuYxbDI+lPirl iH1Ir+ixK3gzazgsCoWExHxxzyuJFrTuYNQXqztwFfIK12AxLbRlfZB/26mv16NDQ20I 3n2a9Ge65BFE8YwdTO38GToRq+gfbZlJsoebHttJPqwARQ0kr/3A6RtWtpF76Qpgy+o8 MizpFOq08VfwAlx87jgHfiY2ikzSwQTXyxEjCVENjK4pwBjhoObXVP03Beg3+FbpnvOm 95fg== 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 d36si5281599ede.44.2019.10.24.09.39.00; Thu, 24 Oct 2019 09:39:01 -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 S2503585AbfJXQiw (ORCPT + 26 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(+) -- 2.17.1 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);