From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 011751CF1CA for ; Wed, 16 May 2018 09:12:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id F238085BD3 for ; Wed, 16 May 2018 09:12:02 +0000 (UTC) Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R__RrZ1YRRqS for ; Wed, 16 May 2018 09:12:02 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 4C5D685B25 for ; Wed, 16 May 2018 09:12:02 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id x12-v6so84124wmc.0 for ; Wed, 16 May 2018 02:12:02 -0700 (PDT) From: Sergio Paracuellos Subject: [PATCH v3 08/11] staging: mt7621-gpio: avoid devm_kzalloc() hidden inside declarations and refactor function a bit Date: Wed, 16 May 2018 11:11:47 +0200 Message-Id: <1526461910-20650-9-git-send-email-sergio.paracuellos@gmail.com> In-Reply-To: <1526461910-20650-1-git-send-email-sergio.paracuellos@gmail.com> References: <1526461910-20650-1-git-send-email-sergio.paracuellos@gmail.com> List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" To: gregkh@linuxfoundation.org Cc: neil@brown.name, driverdev-devel@linuxdriverproject.org Driver probe function includes an allocation using devm_kzalloc which is "hidden" a bit inside the declarations. Extract this to a better place to increase readability. Also because we are allocating zeroed memory 'memset' statement is not needed at all. Condition for checking for a valid gpio id is wrong and it should be greater or equal instead of only greater so update to be the good one. Signed-off-by: Sergio Paracuellos --- drivers/staging/mt7621-gpio/gpio-mt7621.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/staging/mt7621-gpio/gpio-mt7621.c b/drivers/staging/mt7621-gpio/gpio-mt7621.c index c701259..016475f 100644 --- a/drivers/staging/mt7621-gpio/gpio-mt7621.c +++ b/drivers/staging/mt7621-gpio/gpio-mt7621.c @@ -156,17 +156,18 @@ mediatek_gpio_bank_probe(struct platform_device *pdev, struct device_node *bank) { struct mtk_data *gpio_data = dev_get_drvdata(&pdev->dev); const __be32 *id = of_get_property(bank, "reg", NULL); - struct mtk_gc *rg = devm_kzalloc(&pdev->dev, - sizeof(struct mtk_gc), GFP_KERNEL); + struct mtk_gc *rg; int ret; - if (!rg || !id || be32_to_cpu(*id) > MTK_MAX_BANK) + if (!id || be32_to_cpu(*id) >= MTK_MAX_BANK) + return -EINVAL; + + rg = devm_kzalloc(&pdev->dev, sizeof(struct mtk_gc), GFP_KERNEL); + if (!rg) return -ENOMEM; gpio_data->gc_map[be32_to_cpu(*id)] = rg; - memset(rg, 0, sizeof(struct mtk_gc)); - spin_lock_init(&rg->lock); rg->chip.parent = &pdev->dev; -- 2.7.4 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel