From patchwork Fri Nov 1 07:45:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 178256 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp116978ill; Fri, 1 Nov 2019 00:45:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVXbF4KYlBgJI5K8F2p0574pVYHGvfgoH9mD3i9dgPIWTL6lRfByLgOc/EngUp06tPj6qo X-Received: by 2002:a50:fd1a:: with SMTP id i26mr10904380eds.272.1572594349504; Fri, 01 Nov 2019 00:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572594349; cv=none; d=google.com; s=arc-20160816; b=A5inWwoz53tHPwrQ7xR18zTAiFtgsFOqsthSErWNVJ2j4ezlzjW3cEEg2nIgQGN8Z8 dgEcUVhoWDcOYAczngcj4rW/B8P62stFMtIvOVZliHlXjnY/ZtVDxKHWgTMrzxeYflcM nqxXkHurSQ/bx6tA/1XTDT0HqiY1zi3DrKX2PsN7tDNaBKZi3HRFEUjMhyIN75a5Kzke eeG7pET+95dd+xQpZEXGAcUODNrl5f5+RJZ0ESWKjWKf7Pk9Hq/E2aiqTCV6DqkigjXR cXlii+WYXSlDjV5PZL789LlCj2glsgGeZzv2JfhBNVVTbVA0QdbG+3KbN3kI9tiSqsnn YmwQ== 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=GReEFG2GWwJjsYxj+qnWr2ZeJ1W345Xh+fZqhg0GuOc=; b=sWcyrCzakgKwpSvsYIekdml8b09zlvuVVDLN5+DzbL0mXJH+iwHLN1873CDlIG7uw+ MPMSotkKm4WN6dWO+Qw5gOIo/6UE7BELaCSTJwXqz9v7qjSYvPB6RrvDZQMLI6FGJnj9 7RwwnyNYN0e1U68EC/vaLS9iV697eyPF94LrseDDFGzdSnPdjSRl5MQ1sNW5Ibupq97f bzfWM0yZsLw7mhyz35R/DCH6mcguIU79g9Mxbftjal9qzakjCD5+4bFno9Q3M51kAbga uVlLglnOWN0FL6PEtcFquX0M+iuGTHzM4JqueMwaQqMwas1ykws1JMvjt8joCydqYqjo C2tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aPAUMhk6; 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 w18si5188280ejv.378.2019.11.01.00.45.49; Fri, 01 Nov 2019 00:45:49 -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=aPAUMhk6; 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 S1730139AbfKAHpf (ORCPT + 26 others); Fri, 1 Nov 2019 03:45:35 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39639 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730121AbfKAHpb (ORCPT ); Fri, 1 Nov 2019 03:45:31 -0400 Received: by mail-wm1-f65.google.com with SMTP id t26so4168759wmi.4 for ; Fri, 01 Nov 2019 00:45:28 -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=GReEFG2GWwJjsYxj+qnWr2ZeJ1W345Xh+fZqhg0GuOc=; b=aPAUMhk6ayoWZyrvs0fsQnUU17xXjJv6voGdabNYsT7kPSp8UW342XBwFG/EeCKz0M 9HsX/Ldh/pDdk8lDjcmMli0SNg0TYdag8vMTj25aA78BvXaLqt9Cip7XMGccXX3djbMt f5T+xevpesx2ybGhZaHvyv/4lfHjcQ8WKL17xX0pbqQCYyF5U7q2oaX4MLyl5liN0hHz CQpfRklQ5z2fEf9l34Dg4zNLAGIIvGG8s0970wnbzNziW5bYYqeUboSChFg21DExUJgn MmSriuu9eSFRucviBK0WmT8DoZUToeM4JmB7oRR+ek1UV/IoV6ueW0DXiGuiCb9GxbAb /5uQ== 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=GReEFG2GWwJjsYxj+qnWr2ZeJ1W345Xh+fZqhg0GuOc=; b=Yh63qrvRItgZ2YnhCxzKxdz3j2YEId6maq+eC4hwGY3JPw+ZhI9wzJEDcroPii1pwh FAxki0T9J2Tcq9poeKm/ZT6Q3GjcvwFOsWTD+fwo52sVwysr1clg172d/SxNwZCLe+XH AkDkKDxp6icJecGBXgTQVkxwgv+MMH0xwEUmgP2rigEjsInPYSVsc9qej+KKz10Q389P s5ZLpfSZQoEMsmVuDkZLUbrco8sP8mul4itBH6eat8nkUQzw/Q8PnXJ12Am2GYLdWHvC dLBezwxaAzYhBv4bK+4BqVJlArkG+vQePCx1ALQTof7VsX7ftsngMObpvDoJAshW82z6 YYmw== X-Gm-Message-State: APjAAAWmZvAAYo+jGoSYsSuiw3WWFQq1/yj7iynw/iGpFCAJ20R9Htvp gb9Q8KoNnXe5kQFW+cbRzCzRPg== X-Received: by 2002:a1c:808d:: with SMTP id b135mr8624500wmd.175.1572594327746; Fri, 01 Nov 2019 00:45:27 -0700 (PDT) Received: from localhost.localdomain ([2.31.163.64]) by smtp.gmail.com with ESMTPSA id b1sm576215wrw.77.2019.11.01.00.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2019 00:45:27 -0700 (PDT) From: Lee Jones To: daniel.thompson@linaro.org, broonie@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, linus.walleij@linaro.org, baohua@kernel.org, stephan@gerhold.net, Lee Jones Subject: [PATCH v4 05/10] mfd: mfd-core: Protect against NULL call-back function pointer Date: Fri, 1 Nov 2019 07:45:13 +0000 Message-Id: <20191101074518.26228-6-lee.jones@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191101074518.26228-1-lee.jones@linaro.org> References: <20191101074518.26228-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 Reviewed-by: Mark Brown --- 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 23276a80e3b4..96d02b6f06fd 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);