From patchwork Wed Nov 21 18:06:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10692941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DC5C13AD for ; Wed, 21 Nov 2018 18:13:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C50A290D0 for ; Wed, 21 Nov 2018 18:13:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10A332C61B; Wed, 21 Nov 2018 18:13:47 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham 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 BBF80290D0 for ; Wed, 21 Nov 2018 18:13:46 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=vUHDPrwqfQCsohlKpSGD04zxoJQ/6QOb5fo7Ia5JR8o=; b=p4U tk74rYRUKMFHZEICcoZRq+ilTpVNuRhhjnJRWqAOJrZMbyCqaEv79wxLpdpuBs8Hrsppgd2BIgCmo wmnBcqUUgq7I/eM5+yPsAETnqX57lR7VGj2RgjchIw1iLEb6OaJXdyZxxs8XqMmeooCQt6Pym+0xV txYF4MRGItQtzlK9E91agyBvfY3IIgeTx55gpefLeFW9H+begZB7BxZZ6ILCaAwb7mT+naKh2R8ex iRfP8U9egO6kUoukem2dr79kmEO8zTn9gpi7EKbuiFnjiZD49LIYqC1b54fx+1JjHGfH4PPAx2e/4 hxJl4nMuzdtviJ3msfpZcxtwpp+nCbw==; 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 1gPX0S-00011L-V5; Wed, 21 Nov 2018 18:13:44 +0000 Received: from www.osadl.org ([62.245.132.105]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPX0G-0000XJ-Dy; Wed, 21 Nov 2018 18:13:34 +0000 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wALI9BFM006464; Wed, 21 Nov 2018 19:09:11 +0100 From: Nicholas Mc Guire To: Linus Walleij Subject: [PATCH 1/2] gpio: mt7621: report failure of devm_kasprintf() Date: Wed, 21 Nov 2018 19:06:12 +0100 Message-Id: <1542823573-20228-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181121_101332_770156_F35685E3 X-CRM114-Status: UNSURE ( 9.18 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sergio Paracuellos , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , linux-mediatek@lists.infradead.org, Nicholas Mc Guire , Matthias Brugger , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP kasprintf() may return NULL on failure of internal allocation thus the assigned label is not safe if not explicitly checked. On error mediatek_gpio_bank_probe() returns negative values so -ENOMEM in the (unlikely) failure case should be fine here. Signed-off-by: Nicholas Mc Guire Fixes: 4ba9c3afda41 ("gpio: mt7621: Add a driver for MT7621") Reviewed-by: Bartosz Golaszewski Acked-by: Sean Wang --- V2: The dev_err() for the unlikely case of the devm_kasprintf() failing was removed on request from Bartosz Golaszewski Problem located with experimental coccinelle script Patch was compile tested with: omega2p_defconfig, SOC_MT7621=y, GPIOLIB=y, GPIO_MT7621=y Patch is against 4.20-rc3 (localversion-next is next-20181121) drivers/gpio/gpio-mt7621.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c index d72af6f..1ec95bc 100644 --- a/drivers/gpio/gpio-mt7621.c +++ b/drivers/gpio/gpio-mt7621.c @@ -244,6 +244,8 @@ mediatek_gpio_bank_probe(struct device *dev, rg->chip.of_xlate = mediatek_gpio_xlate; rg->chip.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", dev_name(dev), bank); + if (!rg->chip.label) + return -ENOMEM; ret = devm_gpiochip_add_data(dev, &rg->chip, mtk); if (ret < 0) { From patchwork Wed Nov 21 18:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10692939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CD7C13B5 for ; Wed, 21 Nov 2018 18:13:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B51D290D0 for ; Wed, 21 Nov 2018 18:13:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F5A22C61B; Wed, 21 Nov 2018 18:13:46 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham 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 B27BA290D0 for ; Wed, 21 Nov 2018 18:13:45 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=60IZeiqaKdUIch8L0yF3MKeeXIWeGwRsx5qac0asTmU=; b=H2M9lQisDmk5nnQ7yo17zo9Qm1 qbH5C2OWX5I5wC7q1yJ7eef7LDcMikMmfoiEvK4l+E4AS1qQtMOKQx6NB9b1m6+9o+gfl8YNQ2jqm oRw8XK3sSCdNZ0ntvLFTfVLCY1X3B6u9+hTLn3cjCaL+guEzPdMlhP7D82wWIUpZk0VVqkVaNmaEi yqGhhuql78Dl2e2rGZrtXnipq/nC7yUDZHL0FhJNAhbYiYoTj6U0cnfxxsWpND1T5QVp44u8fy8t6 oNwcoK7Q8QMtoibBDI05BFwpcFBtvIxX0Kb4XAL4EwVKjl9D/Dw6dD2DVaj6nAjIriwcDZvCKtUca kzQ2EMBg==; 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 1gPX0M-0000rk-1v; Wed, 21 Nov 2018 18:13:38 +0000 Received: from www.osadl.org ([62.245.132.105]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPX0G-0000eR-Dy; Wed, 21 Nov 2018 18:13:34 +0000 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wALI9BFN006464; Wed, 21 Nov 2018 19:09:16 +0100 From: Nicholas Mc Guire To: Linus Walleij Subject: [PATCH 2/2] gpio: mt7621: pass mediatek_gpio_bank_probe() failure up the stack Date: Wed, 21 Nov 2018 19:06:13 +0100 Message-Id: <1542823573-20228-2-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1542823573-20228-1-git-send-email-hofrat@osadl.org> References: <1542823573-20228-1-git-send-email-hofrat@osadl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181121_101332_776378_60DF5C92 X-CRM114-Status: GOOD ( 10.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sergio Paracuellos , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , linux-mediatek@lists.infradead.org, Nicholas Mc Guire , Matthias Brugger , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The error cases of mediatek_gpio_bank_probe() would go unnoticed (except for the dev_err() messages). The probe function should return an error if one of the banks failed to initialize properly. Signed-off-by: Nicholas Mc Guire Fixes: 4ba9c3afda41 ("gpio: mt7621: Add a driver for MT7621") Reviewed-by: Bartosz Golaszewski --- Patch was compile tested with: omega2p_defconfig, SOC_MT7621=y, GPIOLIB=y, GPIO_MT7621=y Patch is against 4.20-rc3 (localversion-next is next-20181121) drivers/gpio/gpio-mt7621.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c index 1ec95bc..68fca8b 100644 --- a/drivers/gpio/gpio-mt7621.c +++ b/drivers/gpio/gpio-mt7621.c @@ -297,6 +297,7 @@ mediatek_gpio_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct mtk *mtk; int i; + int ret; mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); if (!mtk) @@ -311,8 +312,11 @@ mediatek_gpio_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mtk); mediatek_gpio_irq_chip.name = dev_name(dev); - for (i = 0; i < MTK_BANK_CNT; i++) - mediatek_gpio_bank_probe(dev, np, i); + for (i = 0; i < MTK_BANK_CNT; i++) { + ret = mediatek_gpio_bank_probe(dev, np, i); + if (!ret) + return ret; + } return 0; }