Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5128555yba; Wed, 10 Apr 2019 12:00:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdNENKA1byDpfeAs4hpiPsdBwTHEZ9qx7wpGmmDEhlGq5wiHq2Cjqcn5l4+6EmJkH9mOzH X-Received: by 2002:a63:2c4c:: with SMTP id s73mr37240956pgs.42.1554922815703; Wed, 10 Apr 2019 12:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554922815; cv=none; d=google.com; s=arc-20160816; b=Td3X+CT+1s0f2Ijmh/uTupU+NBRzcsZjVAg9kcUQ6xKgapYumpMChATiXU0VUEGOl3 YmfCAlnz8397ExjPaY3fVHiqenIMFdXKYS+Xm+Bi0LLTx7uEUCmUbwgraPwA1GMzWCy4 wgHF4jgKbWOF4RRw/+EWmTR9NYhE+0LXFbbpotFEH9mSfCH2g3Hlyn5TM27sM//HSyb6 Pdlb9iF4okSaDy3mrN5WxAFWB/WOTJj8tlHet3LRpyEKld4b9XLfPFs6J8/KPXXxjMmg untkOChfyoLxEjQde/35b3UsydgrSCuu69dTDrOrJLnEXB3RPShJaNH9moDP+bXrfL0B Xvcg== 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=c2FEfcVttbNCfJqC2hCYAaLdDZL89jf2XIDcZsihWPM=; b=cgI+Tg/+88n9Oy5CHgpR8D5VAePER2DMEkx9fvAj7u8N0Qq0aqpejEp1LiGGDkEZ1C dRALsNFWYgG9wAXa6NO34iltLSZ1VxRAtOZeLFsb3QA0L1Z3ZWa5mdfUFdhR4mNxHJHe BPs5kHYT2OrkfCADtGYKMs7WjICOBwuV60dZfmomo8kITfLsxh7+rZLRvDsg3M2c+na2 WOr9YpukYph4OwaQZD1WQjeSDphQTb7iB3fXXlhX72YonziifHn3wuf6ogsTUUR31Ck5 Fo//x/+UhqnFWXLNe5ifat5ydJZuhXhRqro0mObcOWLeLVtlNKqX4vb9re0vjp5vwCkr TrdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=g9f3lkU5; 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 l65si33060039plb.338.2019.04.10.11.59.59; Wed, 10 Apr 2019 12:00:15 -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=g9f3lkU5; 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 S2387979AbfDJQ3c (ORCPT + 99 others); Wed, 10 Apr 2019 12:29:32 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36479 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387877AbfDJQ2Z (ORCPT ); Wed, 10 Apr 2019 12:28:25 -0400 Received: by mail-pg1-f193.google.com with SMTP id 85so1871047pgc.3; Wed, 10 Apr 2019 09:28:25 -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=c2FEfcVttbNCfJqC2hCYAaLdDZL89jf2XIDcZsihWPM=; b=g9f3lkU59N+uE6DpaaWLGIA9SIwrj/sxem3hLSydb3IiDmVVSRGek+LpNi6HaTHHfa YNXJ3wf6mSvZ3dHxOq+0l+3bwcfIq22573tm/HCmJdaMut3qd8+36xPFxfsmh5HM+Rbq Zes9fQiADEN7VWibEgfNUOhgOndNtJrHVlEcY8HD+dO/QUWt4FdlRy2Jj1EBwwZJUMtE IONQ6aYXp1BHl+w1sAfkTnbMcNwEH9EoiLgTvqBN3xWJAOgKZc1OFupvskd6/WmFfjLu MYiiS/YFwdddgGU6o/s0pCaDRT6Y3h/bFtx9TDw6JcJ5ljZiSTmoRdAjaDixNnvzDUBA zu+Q== 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=c2FEfcVttbNCfJqC2hCYAaLdDZL89jf2XIDcZsihWPM=; b=CMt10TDLNlPy4WgXJSfha4hpaSNdtlbG5y1o0B/MySQdtgP689g2QL3w31jdDQye2H Hf4MQLiRJ40959ozCVXg0kqpNbqA3LN9wqsplEG7iwVPVbEvqNF9gv25Rf40LLiBmBzH s7ZFOyJg/bCH9MFoR3Qz3sEilz6FFm9ty3yUFWNWULut7Gcd+atSNDWLlk2aECjKsYbt 64Idha75rTaIOtW/U+18LGoZjbS+TVjMd2C2Dk2kOjgTcKOoxhFdGtXt03brSBlD//y3 3FxYk6gE5ueWa2C1YcvIj/TzdOCZ+dFxiIH2RyNZti2KM24T6UmpkQDeLPnhfHX6bf6g KE7w== X-Gm-Message-State: APjAAAXiPMQwsFGpmunEfi7OFbicf1O1diofVoGwyVBx/s6dixWEuROT mCIobN7ZauxyScxHM5asNxI= X-Received: by 2002:a62:1d0d:: with SMTP id d13mr44593907pfd.96.1554913704771; Wed, 10 Apr 2019 09:28:24 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id i1sm68511373pgc.63.2019.04.10.09.28.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 09:28:24 -0700 (PDT) From: Guenter Roeck To: Wim Van Sebroeck Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Jun Nie , Shawn Guo Subject: [PATCH 12/22] watchdog: zx2967_wdt: Convert to use device managed functions and other improvements Date: Wed, 10 Apr 2019 09:27:53 -0700 Message-Id: <1554913683-25454-13-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 - Use local variable 'struct device *dev' consistently - Use devm_watchdog_register_driver() to register watchdog device Cc: Jun Nie Cc: Shawn Guo Signed-off-by: Guenter Roeck --- drivers/watchdog/zx2967_wdt.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/watchdog/zx2967_wdt.c b/drivers/watchdog/zx2967_wdt.c index 9ccc83f526f3..c8549bf07cc9 100644 --- a/drivers/watchdog/zx2967_wdt.c +++ b/drivers/watchdog/zx2967_wdt.c @@ -188,6 +188,11 @@ static void zx2967_wdt_reset_sysctrl(struct device *dev) of_node_put(out_args.np); } +static void zx2967_clk_disable_unprepare(void *data) +{ + clk_disable_unprepare(data); +} + static int zx2967_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -206,7 +211,7 @@ static int zx2967_wdt_probe(struct platform_device *pdev) wdt->wdt_device.timeout = ZX2967_WDT_DEFAULT_TIMEOUT; wdt->wdt_device.max_timeout = ZX2967_WDT_MAX_TIMEOUT; wdt->wdt_device.min_timeout = ZX2967_WDT_MIN_TIMEOUT; - wdt->wdt_device.parent = &pdev->dev; + wdt->wdt_device.parent = dev; wdt->reg_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(wdt->reg_base)) @@ -225,13 +230,16 @@ static int zx2967_wdt_probe(struct platform_device *pdev) dev_err(dev, "failed to enable clock\n"); return ret; } + ret = devm_add_action_or_reset(dev, zx2967_clk_disable_unprepare, + wdt->clock); + if (ret) + return ret; clk_set_rate(wdt->clock, ZX2967_WDT_CLK_FREQ); rstc = devm_reset_control_get_exclusive(dev, NULL); if (IS_ERR(rstc)) { dev_err(dev, "failed to get rstc"); - ret = PTR_ERR(rstc); - goto err; + return PTR_ERR(rstc); } reset_control_assert(rstc); @@ -242,28 +250,14 @@ static int zx2967_wdt_probe(struct platform_device *pdev) ZX2967_WDT_DEFAULT_TIMEOUT, dev); watchdog_set_nowayout(&wdt->wdt_device, WATCHDOG_NOWAYOUT); - ret = watchdog_register_device(&wdt->wdt_device); + ret = devm_watchdog_register_device(dev, &wdt->wdt_device); if (ret) - goto err; + return ret; dev_info(dev, "watchdog enabled (timeout=%d sec, nowayout=%d)", wdt->wdt_device.timeout, WATCHDOG_NOWAYOUT); return 0; - -err: - clk_disable_unprepare(wdt->clock); - return ret; -} - -static int zx2967_wdt_remove(struct platform_device *pdev) -{ - struct zx2967_wdt *wdt = platform_get_drvdata(pdev); - - watchdog_unregister_device(&wdt->wdt_device); - clk_disable_unprepare(wdt->clock); - - return 0; } static const struct of_device_id zx2967_wdt_match[] = { @@ -274,7 +268,6 @@ MODULE_DEVICE_TABLE(of, zx2967_wdt_match); static struct platform_driver zx2967_wdt_driver = { .probe = zx2967_wdt_probe, - .remove = zx2967_wdt_remove, .driver = { .name = "zx2967-wdt", .of_match_table = of_match_ptr(zx2967_wdt_match), -- 2.7.4