Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4105699ybg; Mon, 21 Oct 2019 03:59:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRb2licufNUlIx5KDJVD6/zgHZr63COisLS5//swAJ9ANUkOXzZ3SiA+QvbmoEnMF28wO2 X-Received: by 2002:a17:906:c836:: with SMTP id dd22mr1964754ejb.178.1571655561327; Mon, 21 Oct 2019 03:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571655561; cv=none; d=google.com; s=arc-20160816; b=ZHXCsj8uB44E9MMRmbONVqXTYl6QYjbSMEepvI7HLv5J+ukeARTpdOHvTh4ZKeq4Ra 2SAo9HgnfUCeCXBImcQWTVjhENNqwWj/mgLkbzomEv8qMUQTeiPRsUjd1R2ZWC60q1JQ HnxaGyvkUVpkaumg/Dvrr7vC9FL725kIu0j9eyj+m/niQXNXGeLpEkfyFUuU5coy93fx BO33UlE98ASppfvq0fOkMmQzrLNOJlTjEpuMUVpISYus2kv+qBgbRDC4SGlNnTW6PRye 0FZzeeP3vM6oruhW0vg6tbMT6FmcgXIW3GeoTCTazvY6wfRfF4UySPHTIiKViMLI2Tch Anyg== 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 p9si9690294edc.96.2019.10.21.03.58.58; Mon, 21 Oct 2019 03:59:21 -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 S1728372AbfJUK6j (ORCPT + 99 others); Mon, 21 Oct 2019 06:58:39 -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(+) 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); -- 2.17.1