From patchwork Fri Jun 22 18:31:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10482823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E28160383 for ; Fri, 22 Jun 2018 18:31:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B3F428FEA for ; Fri, 22 Jun 2018 18:31:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FABB28FEE; Fri, 22 Jun 2018 18:31:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B875628FEA for ; Fri, 22 Jun 2018 18:31:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r9wSaK2n9C1X/OFWE3/WiQTp2nTbgIpQec65tvfxj30=; b=PhBALtsPKJiqHl LSc4xF4pFBSs4ZgHJOnFikFkqjchGYZwBKO044/Www0uR6nAdr0dqm9Z3FqUBG+6x/x24ze28PjH1 cvLxDohvNj+oJMRdFqmTv1f4GNDER/dRCtwNwaK74gJYiakuAGtmRkhXkL6M15ksyxKsqPdwXd6/+ mhphPsrh6kAX7tqIY0OCGpdQOszRvMgF8dsoZOYFeLzi6VA8FmdS4DWloNEfVFozQ10y+ujUeYpah YlZ/YXZ8+QmpDkpRMEFwLCYt2A1XqwYRTkruDOUFRBlx4edTeq4VSqppBNE40I3/7e1+hR4r28qpF 9IIdkMMq96hiBuwRYJ+g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWQqf-0000vz-48 for patchwork-linux-mediatek@patchwork.kernel.org; Fri, 22 Jun 2018 18:31:53 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWQqG-0000hV-7o; Fri, 22 Jun 2018 18:31:30 +0000 Received: by mail-pf0-x242.google.com with SMTP id h12-v6so3591685pfk.11; Fri, 22 Jun 2018 11:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Dnlmeh0ETRyTeQmQmJpCWaYnEVSEN/4h7gHXw6oj92o=; b=XZGVo17NoLaFqAfuKkuTDWfQhoF/O6wM5fndQLT2HlHWP26x2HTVUOlKonsPA6teZi vQI2aIzVeVMegWKww5aUEU81iom64CVwEgMHCY1AN+055kWK1MMkKzE75WJYxmXQk0QT I5OS8ZQZ/G3nqGs1auXk4Pi5f9e3/r3+VW78BV421Q49CyBFSLItwb7TwdXzOWRmlzaZ tO7NPe7SOOzeqhFL4YknY5wdoRjvbWbg1fDzmz4U6Pvh//Rwg+FJNidbcRNnx51JCfD/ X4x8p2yG+k06PjxfEMmOQagZW0PJPQ9MCIFtF6bk04iQRRZKxexLJICB8KgD7MdtoRmj kSyg== 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=Dnlmeh0ETRyTeQmQmJpCWaYnEVSEN/4h7gHXw6oj92o=; b=XshOChfuuUfqlsg9rBEi9FbIoNf0mKnUbDqFN8m3HqvL7MgvEaf/MbeTJiN9J8uFt7 jUpFCIl3tSbqx/Bnr8cUkkd5g0tap44181IYn0OwfJn3kfcA842Zjl9q29vJZrPUv+ma jpB/1n2SQHGtoKBOOsqYRaXEaFUI/d+7XI9wF7Y+LP7URdr/jmYC7ITGdABpPlquXHYq kmvfpiQJIwdkPLsxcV76aGR2SrlO8p6idTnpOycWXoFG/EHXSdflpIPbsik9xqtR3ur7 faIaHBY+9y931MQ2adF65gLc5C2uDSnOCw+UdIlzoi54Qnk/BrJ2guvQAiEmfMfFtxE0 4GNQ== X-Gm-Message-State: APt69E3fykLqY9OXFQOEzu88qjHwvGf8cpYT3EVwOJnLPLMpPy/4gpmv wOsXsJBQHj3X2oZPFaG7gHQ= X-Google-Smtp-Source: ADUXVKLWK6fSB6VMB8pTJvG0eYbXanKfPHbMESmANTrhEuzzu59X1diupblMBtkjjpjKbXCwuyDp4Q== X-Received: by 2002:a63:7d4c:: with SMTP id m12-v6mr2361286pgn.201.1529692277076; Fri, 22 Jun 2018 11:31:17 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1511:8de6:27a8:ed13:2ef5]) by smtp.gmail.com with ESMTPSA id r3-v6sm4380740pfl.162.2018.06.22.11.31.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jun 2018 11:31:16 -0700 (PDT) Date: Fri, 22 Jun 2018 11:31:14 -0700 From: Dmitry Torokhov To: Matthias Brugger Subject: Re: [PATCH] input: mtk-pmic-keys: Fix probe when no DT node present Message-ID: <20180622183114.GA92912@dtor-ws> References: <20180622114228.8619-1-matthias.bgg@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180622114228.8619-1-matthias.bgg@gmail.com> User-Agent: Mutt/1.9.2 (2017-12-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180622_113128_285582_C0CDA69B X-CRM114-Status: GOOD ( 19.23 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthias Brugger , chen.zhong@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-input@vger.kernel.org, lee.jones@linaro.org, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Jun 22, 2018 at 01:42:28PM +0200, Matthias Brugger wrote: > The drivers gets probed from a mfd devices. So the driver runs > probe although no DT node exists. This leads to a NULL pointer > dereference in the probe function. Check if a node exists and > error out in case none is present. Hmm, if a cell specifies of_compatible and no such node is present in DT maybe we should bail out in mfd_add_device() instead of pushing the check into individual drivers? Something like: Lee? > > Fixes: 3e9f0b3e2b27 ("input: Add MediaTek PMIC keys support") > Signed-off-by: Matthias Brugger > --- > drivers/input/keyboard/mtk-pmic-keys.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c > index 02c67a1749fc..388043e1939c 100644 > --- a/drivers/input/keyboard/mtk-pmic-keys.c > +++ b/drivers/input/keyboard/mtk-pmic-keys.c > @@ -257,6 +257,9 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev) > const struct of_device_id *of_id = > of_match_device(of_mtk_pmic_keys_match_tbl, &pdev->dev); > > + if (of_id == NULL) > + return -ENODEV; > + > keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL); > if (!keys) > return -ENOMEM; > -- > 2.17.1 > Thanks. diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index 94e3f32ce935..36a5fd98000d 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c @@ -137,6 +137,18 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell, } #endif +static struct device_node *mfd_get_node_for_cell(struct device *parent, + const struct mfd_cell *cell) +{ + struct device_node *np; + + for_each_child_of_node(parent->of_node, np) + if (of_device_is_compatible(np, cell->of_compatible)) + return np; + + return NULL; +} + static int mfd_add_device(struct device *parent, int id, const struct mfd_cell *cell, atomic_t *usage_count, struct resource *mem_base, @@ -144,7 +156,6 @@ static int mfd_add_device(struct device *parent, int id, { struct resource *res; struct platform_device *pdev; - struct device_node *np = NULL; int ret = -ENOMEM; int platform_id; int r; @@ -176,11 +187,11 @@ static int mfd_add_device(struct device *parent, int id, goto fail_res; if (parent->of_node && cell->of_compatible) { - for_each_child_of_node(parent->of_node, np) { - if (of_device_is_compatible(np, cell->of_compatible)) { - pdev->dev.of_node = np; - break; - } + pdev->dev.of_node = mfd_get_node_for_cell(parent, cell); + if (!pdev->dev.of_node) { + dev_err(parent, "unable to locate node for %s (%s)\n", + cell->name, cell->of_compatible); + goto fail_res; } }