Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5120487yba; Wed, 10 Apr 2019 11:47:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoGxrtzh4eurTOgDaTIB/8VN9A9VCmdZeptKqFexCOoTBf3ZxbCXYsW4We6pVRxAE4NSE6 X-Received: by 2002:a63:c10d:: with SMTP id w13mr42689894pgf.311.1554922030774; Wed, 10 Apr 2019 11:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554922030; cv=none; d=google.com; s=arc-20160816; b=Hz3grlhShAc1FXFGxkPvJXvHAzZTJFeusu/8Sr/RnP2Bu7n8VRR2z2Mgj64LpSfeCZ GB5K84L//COYIsmAvKa4+G7Q3/Pfc+SmifHZYk/9xcN0S8/JAg7FDYTnWuJsC2bCnzGc KthvlSAFvKVfBXkkiSQjxzAsd1u/+LOKX0aTSQdI7IQoPF5+qJVPNykNJm3Lomt0tjX+ 9ZoP6ed0WF+r6iTVNMvk7dh2anrVo4E2hHPmLSik4IrAsfFaUW6wJF0zht/PUapzsCEf k3RdPwgCfJ8FKPaTWgTKGqaW45uYGGeTTYOeQt46W7Ej3cH7gUiSaxy2oJdHQ1AezGbd GKLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=orMF7rYuBW2QAgocXGhNUAGTXbgVNrgKUN3myFTKYbI=; b=dQgOooxVRhCyFGdLzuyYIG0NSkNeKvZ8Rx0/d2/pOPvTVQ+wr64fa5a424d/GtM+YT ZV6YSQzy/uQIXTpv0fdkYtaY05W6+I8Qi985TgrVYiWupPqHbTFNXnEn65blGiKMKj8E 8LCnLGnPvuM43B+tICZDShV4S4WivTOxjQoleKZMnNxxscFg3HW1zvP2E0dVgi1JnFeV QvrFgxDkLyDmaoiojuDHx08/6+rqCfGWwjzYGOTJBxRO7zcoRFW1yHGkJw0gc8+zvZvO juiy0w/EVC2sgC5h02/OO/FGo0LyxkCBM+zxjXytxOt4c3CqLCx1DiaopyuBdjhycUsZ ROGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hXw7C9KC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si32463580pgm.373.2019.04.10.11.46.54; Wed, 10 Apr 2019 11:47:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hXw7C9KC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387902AbfDJQ23 (ORCPT + 99 others); Wed, 10 Apr 2019 12:28:29 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44770 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387884AbfDJQ20 (ORCPT ); Wed, 10 Apr 2019 12:28:26 -0400 Received: by mail-pf1-f194.google.com with SMTP id y13so1775129pfm.11; Wed, 10 Apr 2019 09:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=orMF7rYuBW2QAgocXGhNUAGTXbgVNrgKUN3myFTKYbI=; b=hXw7C9KCi6C5kI5hpR/VW7d1TTVAbP32+DfiunuKtqgqY+QY3fb1K7cuKaUjfkXZ+G ZjkBqBJyEy3tXdU112kk2wChv3bk2jnctjbYuu+elfI4tEnKrOcZGK/5cen+GZqkUDLO OsiaUt2LpS2DTKDUe0V+kdugcpfFO3E5xRtC9R37LSkgygtJWHEAUgUNL6wx8ivAvwHJ PF3z7vh7B6zuqV3e+439tbKsTYuBss6mb2m8JlEeVMpO9sZfF955HKjHIrJ37/YD6GZO mBsDjqIHxom9Xa8DPlmISiVtwpzIG2wcafrcOEew7oKkLmwHZhmEo2fOh17+GsFwcUdp ASEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=orMF7rYuBW2QAgocXGhNUAGTXbgVNrgKUN3myFTKYbI=; b=XJs3spII8w7F6ZW/tnEHA6OWi8SrjkxexfBJc5NtQLa91zkw5x7nSoejgRv0S2OSwG VO1B/nV7GwjuQPK/SUbTqjrEgFRlfMICYW9eKf5bVenNoDAkZU8P17FUd9aKCOPiFhU6 vd0JGJZ3W5zsWz91RKHNS0PYCgxBgIJXkMsYOCnFbMdLJ96YFdw1EEi332GddcMIel9B wyZO1BRYfeleJVPEGGdKs+ABUfVFUm199fy9l/I5neDNSlcNq3KJymZWRKAu1pOX/zm0 6pl6s+rYQoEfAvw4yDOFnKc1FB8yikWeCXjm6j2uVH4wvKPAIuGdmJhsX3LTDFBh373r fGqA== X-Gm-Message-State: APjAAAVX8NeXeYmstHkPjy2ruycbnpKzc7AKlI3DXQMNw9RTCo1rPexO 19kOoZKehlSOAkQgZ7vji38= X-Received: by 2002:aa7:91c8:: with SMTP id z8mr44553612pfa.110.1554913706126; Wed, 10 Apr 2019 09:28:26 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id q87sm55726631pfa.133.2019.04.10.09.28.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 09:28:25 -0700 (PDT) From: Guenter Roeck To: Wim Van Sebroeck Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Maxime Coquelin , Alexandre Torgue Subject: [PATCH 13/22] watchdog: stm32_iwdg: Convert to use device managed functions and other improvements Date: Wed, 10 Apr 2019 09:27:54 -0700 Message-Id: <1554913683-25454-14-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554913683-25454-1-git-send-email-linux@roeck-us.net> References: <1554913683-25454-1-git-send-email-linux@roeck-us.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below. The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at https://github.com/groeck/coccinelle-patches - Drop assignments to otherwise unused variables - Drop empty remove function - Use devm_add_action_or_reset() for calls to clk_disable_unprepare - Introduce local variable 'struct device *dev' and use it instead of dereferencing it repeatedly - Use devm_watchdog_register_driver() to register watchdog device Cc: Maxime Coquelin Cc: Alexandre Torgue Signed-off-by: Guenter Roeck --- drivers/watchdog/stm32_iwdg.c | 65 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c index 309563e002b8..68756a40eb36 100644 --- a/drivers/watchdog/stm32_iwdg.c +++ b/drivers/watchdog/stm32_iwdg.c @@ -138,38 +138,52 @@ static int stm32_iwdg_set_timeout(struct watchdog_device *wdd, return 0; } +static void stm32_clk_disable_unprepare(void *data) +{ + clk_disable_unprepare(data); +} + static int stm32_iwdg_clk_init(struct platform_device *pdev, struct stm32_iwdg *wdt) { + struct device *dev = &pdev->dev; u32 ret; - wdt->clk_lsi = devm_clk_get(&pdev->dev, "lsi"); + wdt->clk_lsi = devm_clk_get(dev, "lsi"); if (IS_ERR(wdt->clk_lsi)) { - dev_err(&pdev->dev, "Unable to get lsi clock\n"); + dev_err(dev, "Unable to get lsi clock\n"); return PTR_ERR(wdt->clk_lsi); } /* optional peripheral clock */ if (wdt->has_pclk) { - wdt->clk_pclk = devm_clk_get(&pdev->dev, "pclk"); + wdt->clk_pclk = devm_clk_get(dev, "pclk"); if (IS_ERR(wdt->clk_pclk)) { - dev_err(&pdev->dev, "Unable to get pclk clock\n"); + dev_err(dev, "Unable to get pclk clock\n"); return PTR_ERR(wdt->clk_pclk); } ret = clk_prepare_enable(wdt->clk_pclk); if (ret) { - dev_err(&pdev->dev, "Unable to prepare pclk clock\n"); + dev_err(dev, "Unable to prepare pclk clock\n"); return ret; } + ret = devm_add_action_or_reset(dev, + stm32_clk_disable_unprepare, + wdt->clk_pclk); + if (ret) + return ret; } ret = clk_prepare_enable(wdt->clk_lsi); if (ret) { - dev_err(&pdev->dev, "Unable to prepare lsi clock\n"); - clk_disable_unprepare(wdt->clk_pclk); + dev_err(dev, "Unable to prepare lsi clock\n"); return ret; } + ret = devm_add_action_or_reset(dev, stm32_clk_disable_unprepare, + wdt->clk_lsi); + if (ret) + return ret; wdt->rate = clk_get_rate(wdt->clk_lsi); @@ -199,16 +213,17 @@ MODULE_DEVICE_TABLE(of, stm32_iwdg_of_match); static int stm32_iwdg_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct watchdog_device *wdd; const struct of_device_id *match; struct stm32_iwdg *wdt; int ret; - match = of_match_device(stm32_iwdg_of_match, &pdev->dev); + match = of_match_device(stm32_iwdg_of_match, dev); if (!match) return -ENODEV; - wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); if (!wdt) return -ENOMEM; @@ -217,7 +232,7 @@ static int stm32_iwdg_probe(struct platform_device *pdev) /* This is the timer base. */ wdt->regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(wdt->regs)) { - dev_err(&pdev->dev, "Could not get resource\n"); + dev_err(dev, "Could not get resource\n"); return PTR_ERR(wdt->regs); } @@ -231,46 +246,28 @@ static int stm32_iwdg_probe(struct platform_device *pdev) wdd->ops = &stm32_iwdg_ops; wdd->min_timeout = ((RLR_MIN + 1) * 256) / wdt->rate; wdd->max_hw_heartbeat_ms = ((RLR_MAX + 1) * 256 * 1000) / wdt->rate; - wdd->parent = &pdev->dev; + wdd->parent = dev; watchdog_set_drvdata(wdd, wdt); watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT); - ret = watchdog_init_timeout(wdd, 0, &pdev->dev); + ret = watchdog_init_timeout(wdd, 0, dev); if (ret) - dev_warn(&pdev->dev, - "unable to set timeout value, using default\n"); + dev_warn(dev, "unable to set timeout value, using default\n"); - ret = watchdog_register_device(wdd); + ret = devm_watchdog_register_device(dev, wdd); if (ret) { - dev_err(&pdev->dev, "failed to register watchdog device\n"); - goto err; + dev_err(dev, "failed to register watchdog device\n"); + return ret; } platform_set_drvdata(pdev, wdt); return 0; -err: - clk_disable_unprepare(wdt->clk_lsi); - clk_disable_unprepare(wdt->clk_pclk); - - return ret; -} - -static int stm32_iwdg_remove(struct platform_device *pdev) -{ - struct stm32_iwdg *wdt = platform_get_drvdata(pdev); - - watchdog_unregister_device(&wdt->wdd); - clk_disable_unprepare(wdt->clk_lsi); - clk_disable_unprepare(wdt->clk_pclk); - - return 0; } static struct platform_driver stm32_iwdg_driver = { .probe = stm32_iwdg_probe, - .remove = stm32_iwdg_remove, .driver = { .name = "iwdg", .of_match_table = of_match_ptr(stm32_iwdg_of_match), -- 2.7.4