Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4206096ybg; Mon, 21 Oct 2019 05:33:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfukmQN8eclSMXbN77GQ5UB3ylQdGiC41dR22fNzBvki6Zzj4/rNZ3OkRb4yx0FkDMdZFB X-Received: by 2002:a17:907:213c:: with SMTP id qo28mr6859673ejb.43.1571661196692; Mon, 21 Oct 2019 05:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571661196; cv=none; d=google.com; s=arc-20160816; b=OPIW5L6gCyYyyZoRd2bXToHX/N5ED7M6ypNfJEIvdGpZbN7e+P/R4UJEFmyZ71kWp3 yZlvsfIiTLaDNfCtTeBV/6lCzh89Qp85wLVDylr74W5olSoPUrQ/Vi2G8mnFR/qu5QmX sp58f6wiu0iIlUssRFCrDKAixTocPiGlpOkZKDiG/2yWaUPBauMDDbmgbh+12lUmYIEO qwW1VFaGWMfZXNS20BAxsaJ1r4vQXJ4YIQiwTX8MN/YoK1Obb8TavpHSzGm6W7z7nlb/ GYiKYbSBx+9sOlD5MFtiqjd10KgnTxUqxphVIN9H5pl51hggcrx4tIEuvqjKd9K5AQy3 MC/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YSNbD0PByWlljM0tltuyIHBfRs/cFkXbsMwoXfP9xNQ=; b=dWPIKz79Uz16i6CAF8SYYnNoTzmiIDf3QgPAmQG3aReUP3yVxn5Pr3IH/atBuDwOjZ 762GTKe2beVzXPXIUkZ+W/wuT7o6ZH/PihEtf04P5unXZgUzxSCoCTQHAQ7yGJ3VDNF8 1BIM2+fHNQTY8yhjhAIdrxxnMUJYtGX8TlgO38ZS5HQyt+YmcBvdgLMq1PWC+2LnQdfG +Zp3kmXBqMj8K1/2+LjDmIfl5Gy05EyBpmbhQN39251ws4vqNZk9hpbL/yTZNlHEFBxM CkKHQVUsfqqBhJOAw5USt2HsgA5NDDC4L8Dnbwa59bpCytOejgMBg6ZhnpqnR1n9htl0 6+dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S+Mwsua5; 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 w12si8171121ejb.303.2019.10.21.05.32.53; Mon, 21 Oct 2019 05:33:16 -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=S+Mwsua5; 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 S1728345AbfJUMck (ORCPT + 99 others); Mon, 21 Oct 2019 08:32:40 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33362 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727322AbfJUMck (ORCPT ); Mon, 21 Oct 2019 08:32:40 -0400 Received: by mail-wm1-f68.google.com with SMTP id 6so1272010wmf.0 for ; Mon, 21 Oct 2019 05:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YSNbD0PByWlljM0tltuyIHBfRs/cFkXbsMwoXfP9xNQ=; b=S+Mwsua59XN67/GSiILSsQdKYodDH+CWLAETt/iEQ+WCYBv4iADwrNG/eACZ58pyrj BO6b5GYW55DhQ9GoxgH0oQHKr53qMOPogTY/8lO7gPRL+o8LeWFgPZC/FWShX4mq/rZu MO2cHAEvmVRiaZIixjEGDEilcJXjvaXa6Ne+MGi+PqqerpCjH9BtFho3C59jY5aqbZn6 6cyBPXlfjA42ARw9f1uowEi9ddN0u8Ps2Y9xlcdx893lCND3OolalLFeGQ4FrEbO6EJe +hCwEH3Fs4tmWyNSS/8hV4joXu7lHI6DVwLY7QPXzX62J1zKAKRTM6GfC95aoXAfl1Ga GnmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YSNbD0PByWlljM0tltuyIHBfRs/cFkXbsMwoXfP9xNQ=; b=k++BKbsBc5FUEh14c+RsWlTydVjqBKfX1tkOHHRYf4sczS/rfh8u9VE+ZASY9/IOEA 7O62rTqnG0IiBTOtz8T9e7ljT8a8ujlCN1bklLJgCfQd+ArhUIIHK8adaflAGLS003AF 0v5x87ovklkhKgSlNCthUGbnRE2+i5czP0zf4rTteo3p1RxjmjPc8RRCfA9pagjNUwTP Rb5XgWI3q+qSfk01xZL3EyrIMAF9sv2Gl95HarILVFnimm6SUIJ7qcStR88ehEHhL6Af M6PWfzJ/JEoFI3CFv16B+MWpBfpWJs7Rw53MLz1jVwYOrGiTRz/L9xNThV+WyYJ0eAJu z+FA== X-Gm-Message-State: APjAAAXcpp/LD5wvOz72lpSvSpRskSg8wFqbfMZzv7w5U1xlVOHicxFF JtQjHqCnQiNN/GeaA/PXBY0Q6A== X-Received: by 2002:a1c:108:: with SMTP id 8mr10489788wmb.25.1571661157724; Mon, 21 Oct 2019 05:32:37 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id s13sm13453572wmc.28.2019.10.21.05.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 05:32:37 -0700 (PDT) Date: Mon, 21 Oct 2019 13:32:35 +0100 From: Daniel Thompson To: Lee Jones Cc: arnd@arndb.de, broonie@kernel.org, linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, baohua@kernel.org, stephan@gerhold.net Subject: Re: [PATCH v2 7/9] mfd: mfd-core: Protect against NULL call-back function pointer Message-ID: <20191021123235.royyfp4mxrvsgioh@holly.lan> References: <20191021105822.20271-1-lee.jones@linaro.org> <20191021105822.20271-8-lee.jones@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191021105822.20271-8-lee.jones@linaro.org> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 21, 2019 at 11:58:20AM +0100, Lee Jones wrote: > 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) { Oops. Cancel the R-B: ;-). Shouldn't this be !cell->disable() ? Daniel. > + 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 >