From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 58ADE1C0749 for ; Sun, 20 May 2018 11:03:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 5601889CF0 for ; Sun, 20 May 2018 11:03:17 +0000 (UTC) Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I8+G2v4o63C1 for ; Sun, 20 May 2018 11:03:16 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by hemlock.osuosl.org (Postfix) with ESMTPS id A415889CE8 for ; Sun, 20 May 2018 11:03:16 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id t16-v6so10068267wrm.9 for ; Sun, 20 May 2018 04:03:16 -0700 (PDT) From: Sergio Paracuellos Subject: [PATCH v5 07/10] staging: mt7621-gpio: avoid devm_kzalloc() hidden inside declarations and refactor function a bit Date: Sun, 20 May 2018 13:02:57 +0200 Message-Id: <1526814180-19486-8-git-send-email-sergio.paracuellos@gmail.com> In-Reply-To: <1526814180-19486-1-git-send-email-sergio.paracuellos@gmail.com> References: <87d0xq1wmz.fsf@notabene.neil.brown.name> <1526814180-19486-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 077a7c2..bbe6cce 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