From patchwork Mon Oct 21 10:58:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 177063 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3245445ill; Mon, 21 Oct 2019 03:58:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHcI0JEjxhVp/rtaK2QH5Hvt7pV1KCZo0Js1sqYdq5zhekMmcUlL2Kf/KiEMA7rVGrHL6i X-Received: by 2002:aa7:d582:: with SMTP id r2mr24679323edq.196.1571655523292; Mon, 21 Oct 2019 03:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571655523; cv=none; d=google.com; s=arc-20160816; b=OQqo3r25XsVsbJKI27P9OBTu/6JtSoRWWDa6V6voTCel2xmx6axqQdpZOGGPqj/4yY aaScvM1APej8nmSCr3wgasJmiljXbBh0U/CHaCo1geuo/TuExHFg6+pv9KIXOCZaKr30 8rjfU7K3h5Lob61RqIzqDCqNgaHr8lIANqq7bHYCsplKoU496ixBR5W7KDmp6+N67RSa wIRMBR5R38koQ75+2y/ZBaSLHF1FVPFVdbp6N51BAD0uwK7rll0zlT4Vo5ZpltmGjNrP h3cmD15hbQ9c1wNGg4PYOH46wmRLfM3s86z7M51/m7L+PjUf3ShChAcpmu7gAivlSlNh W9OA== 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=OylZk9s0mis8tzuGBIwAaa88loW1Yq19LfmLj+u4mfs=; b=k5HC6/NyXG/0XE7/3q9iBfQQX5/qilbx62cFGd9KWNIgRHc1v/A9ElLe8j7rHlKttu xMtO3vy+FWDIx3MET4VTw/GKfakqbOZn80hh0aMzCQD8hbpPEhIF1SSSbfcZVWCDv+T/ dY1bMNWxtMyLzis3z9mozLMqzK4sys4prNTuSm99hRBC6qe0woKuuQAkvyJqisWDesxC KrYmjXQ5/pVsrW2GqlHh03GqNVSt+K1iWk/AmtFWMLNvpdRqNtPrp8TQX4Pnw38G0Kdo 2d70kUPDQF2dZvl4+9XBfiq/B8Wrhq0qSYnK21szio39SJOh+rn5j9Xrosy+X/i1tcKG V8Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hjbd4jzP; 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 o21si852687eja.318.2019.10.21.03.58.42; Mon, 21 Oct 2019 03:58:43 -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=hjbd4jzP; 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 S1728378AbfJUK6k (ORCPT + 26 others); Mon, 21 Oct 2019 06:58:40 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33898 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728334AbfJUK6e (ORCPT ); Mon, 21 Oct 2019 06:58:34 -0400 Received: by mail-wr1-f68.google.com with SMTP id t16so8283216wrr.1 for ; Mon, 21 Oct 2019 03:58:33 -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=OylZk9s0mis8tzuGBIwAaa88loW1Yq19LfmLj+u4mfs=; b=hjbd4jzPeI1PUWLlYV4B8LpdZp+xJ8qe9umoadGdA9E9h5uyWAn+m4H6FUYmLJdd4J 0HxB57wjYo23ive7bR5mSTDVnyms+GgEFeZECTnwOrZlvN7jbloHloiEiUlKkISk4LIO osY7YZU9gXM6dy41N1p5yl3bu2LkA2fiuxLqwBQqjQD4IFUBxfKuXasoBn2UcVT37Z79 8s9spHNbvhlSqirIuhbUceepbMrutWVFNZ4PGKN1ypMAPZ1sC2zc2EueBqoiG1YbJP2t UcbZenefQ1KTENMJJ52x5nF8UKFG8jUBzrieioNMqQE8qMh8wV6zhiXRAdpnG+PSa4ml fbQA== 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=OylZk9s0mis8tzuGBIwAaa88loW1Yq19LfmLj+u4mfs=; b=VHe8f6/IZeHwcqOA+wdxiDAfbfwOxMNetZ4OoeHqYK7/MILfehHRM1MBlpiJejQOB1 Uw75UgWCd1DKTO6bYrXo962Eb4C5fZcXKQGdu42+MSitBM5ZgunXUQyBdaXfDChPiWm2 d4PjG16G2Ves0IkEowkpkogJngzKmLpnjf/RTp1F2/Dg6Sv0BLbnxnu1hXVT2NtHFgHB JBw2BeotJLtIzTNOx6L5Fwan3tyliBYzlVoAIDC6OvvWueE0HwIs44px/XcxR1Ut6A8G tVrwfmNjWpe6SZ/M6GDRJtsYMVEiR19QBzLDIIeK5JxcQOyCeD0XfDG/rsuEvWO3bwas b3fw== X-Gm-Message-State: APjAAAUQt8Yxi98EqjDt+Rp+ovTtjuEp7LVK+CieUoMl1k1DvclsXfcK Z0Lay6cYnVnIDTyrwoEcbh2s8w== X-Received: by 2002:adf:f004:: with SMTP id j4mr20804975wro.68.1571655512433; Mon, 21 Oct 2019 03:58:32 -0700 (PDT) Received: from localhost.localdomain ([95.149.164.99]) by smtp.gmail.com with ESMTPSA id q22sm12544289wmj.31.2019.10.21.03.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 03:58:32 -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 v2 7/9] mfd: mfd-core: Protect against NULL call-back function pointer Date: Mon, 21 Oct 2019 11:58:20 +0100 Message-Id: <20191021105822.20271-8-lee.jones@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191021105822.20271-1-lee.jones@linaro.org> References: <20191021105822.20271-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 --- drivers/mfd/mfd-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.17.1 Reviewed-by: Daniel Thompson diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index 8126665bb2d8..90b43b44a15a 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->enable) { + 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);