From patchwork Fri Aug 6 08:12:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 493212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F5DEC432BE for ; Fri, 6 Aug 2021 08:14:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55A1360238 for ; Fri, 6 Aug 2021 08:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243507AbhHFIO4 (ORCPT ); Fri, 6 Aug 2021 04:14:56 -0400 Received: from esa.microchip.iphmx.com ([68.232.153.233]:20755 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243470AbhHFIOx (ORCPT ); Fri, 6 Aug 2021 04:14:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1628237678; x=1659773678; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N4i5dp2gK7qlOFPjMFTn8fmP64FDDZe/f83m5Oe+rsU=; b=OQYW0eYm5aHQPq9r1iW7VkLIVUf/H5NOtyZQgtoMHKWFi7nB7Ci3zZob UFSZPOYm+BriU1qyBQFhFa1HtQzDM9KBWtqcXgXG8FaiBL6YEJPoxkaG2 Yh1fz/Ftgz0Hgng06Du4PQWN4cJgD7NlPI8kbB0AqVGsqNfvbX2qwswfH d+XS/3L4+FfaGmZvRJvyRiNuevDO4Wx0zvOltxyJsaMfKrSW/OiRwA71c K5gWYS+DwrueZQtR+eEuKUgRvWNCpgAZkvEu0wwEEVSQSMC7N8XQ+OECu VFVej7bzmUwyMavpcRSPgLv56JVPRcYqboSYFgbafvcvXVWmiKJKC23/M Q==; IronPort-SDR: XOfLv6bQFzzchtZ76lbSUmJmuAuLhwXQ894qFO/GyLCQ1+l4qolD1TdtgldwQoGJiOtsKXY+Tl Zcp8z4rSLcOzwhhcmcCARYOjmrsS29jksL/uw1vgq1YzIjvYBED3T8xr2BceR9IrTq2LTZjoJg vVgcqFBhgikZtcmrZELS/s3ATcKqEM2GydvfcOQw8sNijFBQfL4nNc+3/tdZxilngPxEJ0328z br/+HbVYdasbQjKePHoSf79uc4fjvodPoDzp8+mZEy7b0cD4OWYGOrIzD+LV9b/rBY77uwUhya RSJ/3fQHyxn04aXcLCG1kDRH X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="131820906" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 06 Aug 2021 01:14:37 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 6 Aug 2021 01:14:37 -0700 Received: from m18063-ThinkPad-T460p.mchp-main.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Fri, 6 Aug 2021 01:14:35 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH 1/3] wilc1000: use goto labels on error path Date: Fri, 6 Aug 2021 11:12:27 +0300 Message-ID: <20210806081229.721731-2-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210806081229.721731-1-claudiu.beznea@microchip.com> References: <20210806081229.721731-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use goto labels on error path for probe functions. This makes code easier to read. With this introduce also netdev_cleanup and call it where necessary. Signed-off-by: Claudiu Beznea --- drivers/net/wireless/microchip/wilc1000/sdio.c | 16 ++++++++++------ drivers/net/wireless/microchip/wilc1000/spi.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/microchip/wilc1000/sdio.c b/drivers/net/wireless/microchip/wilc1000/sdio.c index e14b9fc2c67a..d11f245542e7 100644 --- a/drivers/net/wireless/microchip/wilc1000/sdio.c +++ b/drivers/net/wireless/microchip/wilc1000/sdio.c @@ -129,10 +129,8 @@ static int wilc_sdio_probe(struct sdio_func *func, ret = wilc_cfg80211_init(&wilc, &func->dev, WILC_HIF_SDIO, &wilc_hif_sdio); - if (ret) { - kfree(sdio_priv); - return ret; - } + if (ret) + goto free; if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) { struct device_node *np = func->card->dev.of_node; @@ -150,13 +148,19 @@ static int wilc_sdio_probe(struct sdio_func *func, wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc"); if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) { - kfree(sdio_priv); - return -EPROBE_DEFER; + ret = -EPROBE_DEFER; + goto netdev_cleanup; } else if (!IS_ERR(wilc->rtc_clk)) clk_prepare_enable(wilc->rtc_clk); dev_info(&func->dev, "Driver Initializing success\n"); return 0; + +netdev_cleanup: + wilc_netdev_cleanup(wilc); +free: + kfree(sdio_priv); + return ret; } static void wilc_sdio_remove(struct sdio_func *func) diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c index 8e9aaf03a6fa..23d811b2b925 100644 --- a/drivers/net/wireless/microchip/wilc1000/spi.c +++ b/drivers/net/wireless/microchip/wilc1000/spi.c @@ -154,10 +154,8 @@ static int wilc_bus_probe(struct spi_device *spi) return -ENOMEM; ret = wilc_cfg80211_init(&wilc, &spi->dev, WILC_HIF_SPI, &wilc_hif_spi); - if (ret) { - kfree(spi_priv); - return ret; - } + if (ret) + goto free; spi_set_drvdata(spi, wilc); wilc->dev = &spi->dev; @@ -166,12 +164,18 @@ static int wilc_bus_probe(struct spi_device *spi) wilc->rtc_clk = devm_clk_get(&spi->dev, "rtc"); if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) { - kfree(spi_priv); - return -EPROBE_DEFER; + ret = -EPROBE_DEFER; + goto netdev_cleanup; } else if (!IS_ERR(wilc->rtc_clk)) clk_prepare_enable(wilc->rtc_clk); return 0; + +netdev_cleanup: + wilc_netdev_cleanup(wilc); +free: + kfree(spi_priv); + return ret; } static int wilc_bus_remove(struct spi_device *spi) From patchwork Fri Aug 6 08:12:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 493211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A45AEC4338F for ; Fri, 6 Aug 2021 08:14:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88DE0611F2 for ; Fri, 6 Aug 2021 08:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243722AbhHFIPG (ORCPT ); Fri, 6 Aug 2021 04:15:06 -0400 Received: from esa.microchip.iphmx.com ([68.232.153.233]:24593 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243470AbhHFIPA (ORCPT ); Fri, 6 Aug 2021 04:15:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1628237685; x=1659773685; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vh/BL0aX8xxc9KpUT74mE1eVjgLeMpUkwiTiAs0EAkU=; b=w26awP+ec+4u+8pWrl/943+tqcGJ7E0YD5uMR2AF0pMfy6LeXvlCNaiw SpxviWPCLL+jd/cHS6P6fsE5PulQ+RoooTQkozvyaaZfSNCWWudvYD8uz TYV8bHhAKUoUnRBS0B8XB71sCGUmrRmAsUT8f2vtQ8l3bfzS1AyzzPy/2 nHJ4afp0MvnmLtqG1jTXvIIK7XULk5MFYgspEjngRsuaJ4b2XN++Ry2a4 Q9Kwvouh9Hy53ut1cCsjVo67B4I5kiryO7oEAIzQx3qU7Rr+WwDhWIlGx JJh4XA5JNKj4R3CnUwrQg/PcjWhPySd1jqlJGNMWwenU/689HY9+RJ+St w==; IronPort-SDR: 56qDI2tzlZc5Xe3Btz6aE9Hg3kpD/7R6mUnQhSsq5ZmOCvfH0sLwu8QhGSSD5Kf58fC6i182Be bD/x+84LZZLYo7xNjQMVad+6+bqXgjsDUojC2BSspoqR9/sKcO3tffdcIPbSTFQtCzsYl49qSj /F/vNfaaxWsuRyNCqJdA69VHE+4XDJPQrYmBWUabXtt6XDMp4V3RZ5O+m1d3h9YdNsluDi7ooY Gsuz1+hU+k0bY/eS6L+GUzIbYxtAb+rjCamo6yZFVwDBfqtfZR7HAEkZ8AWrQXNSPHMM7b1aPB ISNLtFmuJ8wtbot5O8y4nVaq X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="139048860" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 06 Aug 2021 01:14:42 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 6 Aug 2021 01:14:42 -0700 Received: from m18063-ThinkPad-T460p.mchp-main.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Fri, 6 Aug 2021 01:14:40 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH 3/3] wilc1000: use devm_clk_get_optional() Date: Fri, 6 Aug 2021 11:12:29 +0300 Message-ID: <20210806081229.721731-4-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210806081229.721731-1-claudiu.beznea@microchip.com> References: <20210806081229.721731-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use devm_clk_get_optional() for rtc clock: it simplifies a bit the code. Signed-off-by: Claudiu Beznea --- drivers/net/wireless/microchip/wilc1000/sdio.c | 14 ++++++-------- drivers/net/wireless/microchip/wilc1000/spi.c | 15 +++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/microchip/wilc1000/sdio.c b/drivers/net/wireless/microchip/wilc1000/sdio.c index d1fd182bbbff..42e03a701ae1 100644 --- a/drivers/net/wireless/microchip/wilc1000/sdio.c +++ b/drivers/net/wireless/microchip/wilc1000/sdio.c @@ -146,12 +146,12 @@ static int wilc_sdio_probe(struct sdio_func *func, wilc->bus_data = sdio_priv; wilc->dev = &func->dev; - wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc"); - if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) { - ret = -EPROBE_DEFER; + wilc->rtc_clk = devm_clk_get_optional(&func->card->dev, "rtc"); + if (IS_ERR(wilc->rtc_clk)) { + ret = PTR_ERR(wilc->rtc_clk); goto dispose_irq; - } else if (!IS_ERR(wilc->rtc_clk)) - clk_prepare_enable(wilc->rtc_clk); + } + clk_prepare_enable(wilc->rtc_clk); dev_info(&func->dev, "Driver Initializing success\n"); return 0; @@ -168,9 +168,7 @@ static void wilc_sdio_remove(struct sdio_func *func) { struct wilc *wilc = sdio_get_drvdata(func); - if (!IS_ERR(wilc->rtc_clk)) - clk_disable_unprepare(wilc->rtc_clk); - + clk_disable_unprepare(wilc->rtc_clk); wilc_netdev_cleanup(wilc); } diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c index 23d811b2b925..8b180c29d682 100644 --- a/drivers/net/wireless/microchip/wilc1000/spi.c +++ b/drivers/net/wireless/microchip/wilc1000/spi.c @@ -162,12 +162,12 @@ static int wilc_bus_probe(struct spi_device *spi) wilc->bus_data = spi_priv; wilc->dev_irq_num = spi->irq; - wilc->rtc_clk = devm_clk_get(&spi->dev, "rtc"); - if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) { - ret = -EPROBE_DEFER; + wilc->rtc_clk = devm_clk_get_optional(&spi->dev, "rtc"); + if (IS_ERR(wilc->rtc_clk)) { + ret = PTR_ERR(wilc->rtc_clk); goto netdev_cleanup; - } else if (!IS_ERR(wilc->rtc_clk)) - clk_prepare_enable(wilc->rtc_clk); + } + clk_prepare_enable(wilc->rtc_clk); return 0; @@ -182,10 +182,9 @@ static int wilc_bus_remove(struct spi_device *spi) { struct wilc *wilc = spi_get_drvdata(spi); - if (!IS_ERR(wilc->rtc_clk)) - clk_disable_unprepare(wilc->rtc_clk); - + clk_disable_unprepare(wilc->rtc_clk); wilc_netdev_cleanup(wilc); + return 0; }