Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3178124yba; Mon, 8 Apr 2019 12:51:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvbLBlC71nF2ia0ajfhFto4KDVj9LfL02/Jyew+MFzpGPuJsXo8naqD+LXdGiLmiveOkdB X-Received: by 2002:a63:c302:: with SMTP id c2mr30675263pgd.235.1554753072803; Mon, 08 Apr 2019 12:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554753072; cv=none; d=google.com; s=arc-20160816; b=GrLkSXbYwbrnbNTv9YSeUaCpcMnKI6rsJN61+PYisp9FUKoGyeXgHr9oFC7YlzlB+9 t2PnaVhNrqhHhyZwY00MM/Eduw66yudV0X9MvgN1DOR1rDYD6V+HbEyCOO5t2MhWytqX NnNeG/3n0TLLlEKVdbidABsRwse2j+fYsaGQb1mBW5J6sin4WKtJbztMlIWc7QiSnuDv rGnCIveHBcYZ8oN284NFhSlfAkHkLVldBKusKoQUJfQx9S6x5NNKAt0uddlxRt9veKUe /t4yNIDPJXE1HQ3BIBB0XCws/khDd1yumkfzP5obPsmTKVZAviIvwQqI1d8KWoL4VlMF fygQ== 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=Jneh01n1+bIhANgepGSuhAjCJdMw/IuW338uETIBMa8=; b=MzQnJeTFZAt60GYvVY+4aQnch+9bivPZwTMRYE+tYhploJuMLslaIGDBpU1YgqKLLr +WqTeFFYP34VG96j7L6/qHio+nW6m2vfXMKncndeMYI7J67FKo/dBJFtnllTnVioeQ4i d7+kqFhEQ5xYCCsUFM1oyST+CT5hscsMFtcFKzuFMB/PBfzFsPFzy6fiDGBo81I0364C lzm2bduKJOohFeONFzSd1Q3yhjMph6u42Aj+UYS79IKqXiG34PQmnxtxwnNT2A96lXP8 c6ZKVef45Lp6IQuZeMiJLZUjuD0rt47b22GtZxRpqN/vYdLDQDnHaBjUti88NxBsusZU F1Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=N4LymmXz; 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 h10si9891276pll.251.2019.04.08.12.50.57; Mon, 08 Apr 2019 12:51:12 -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=N4LymmXz; 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 S1729363AbfDHTlZ (ORCPT + 99 others); Mon, 8 Apr 2019 15:41:25 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45907 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728548AbfDHTjo (ORCPT ); Mon, 8 Apr 2019 15:39:44 -0400 Received: by mail-pl1-f196.google.com with SMTP id bf11so7891432plb.12; Mon, 08 Apr 2019 12:39:43 -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=Jneh01n1+bIhANgepGSuhAjCJdMw/IuW338uETIBMa8=; b=N4LymmXzj+cfs0sFJ+tcmMXo15eMUNCQAdAfR9ZvQAhNz4WWzE710lnjAVplzdAI4s p5jDuXvGl1WWIir/esDEUMoPPMuNsMYtiFb28JPdnafAjnzUvUKIDDJRDyqk0w8cGKdH kQCy4HMEehk2AUZ2e855/wyxXcoCuVn/JBDOsYWJFeIxHAOAktKtTnXWrMNHzFnIE1hU 83fdAV7ppxUkO9NL1uOtw2I/q0WIoyMIX+T3UZlmA2DVrkHMFQTQ1lrp6YwK8xV0Txu7 EszVtobE1bTijON+tgeCvvbrXy7E2+C2Sf+cR9JsRDJg3MkUYcJdx8xCVVVDgcprv7IK hiCQ== 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=Jneh01n1+bIhANgepGSuhAjCJdMw/IuW338uETIBMa8=; b=Gadin6sJxlMRblGuf5JfJWc/THNE2uWJUwUrHZUu6sfphmcvAVXi+soWU6ZUART7jW yFcG6VHGhhqanjG/x+sHoblvpqQzKugxO3C20wZTYtl/I5L1WGDSFDvj+tboPpRsT7Wo gsH5Efk3uO3pZaBavmiTq8MNMjjqSBmxflNYbNeY4+8HbugF4ewdGmEEDYArRlV843VQ fRrORCIpizNKCO73p1icZO/4huH/KnlhaX2RQF2hLrkwEiZ8Pf1M+LQIzlJ/YZKQncE3 EgdCwTAqTsuiuMB02iyg4KrXF8sgg8RSvc0jOlUHbkZ3HB0QQKFEIdMU3MDmSbkQ33/B dVpg== X-Gm-Message-State: APjAAAVgeYe+d3u9RrVKNDOAqw2Xk1cmrIJO/hYf1enoaKNSubaP/qnM a0Yb6yZ5HWgKbhrYnpe+QYU= X-Received: by 2002:a17:902:4101:: with SMTP id e1mr31119676pld.25.1554752382864; Mon, 08 Apr 2019 12:39:42 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id b2sm36481508pfo.150.2019.04.08.12.39.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Apr 2019 12:39:42 -0700 (PDT) From: Guenter Roeck To: Wim Van Sebroeck Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH 04/22] watchdog: atlas7_wdt: Convert to use device managed functions and other improvements Date: Mon, 8 Apr 2019 12:38:28 -0700 Message-Id: <1554752326-13319-5-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554752326-13319-1-git-send-email-linux@roeck-us.net> References: <1554752326-13319-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 unnecessary braces around conditional return statements - Drop empty remove function - Use devm_add_action_or_reset() for calls to clk_disable_unprepare - Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)' - Introduce local variable 'struct device *dev' and use it instead of dereferencing it repeatedly - Use devm_watchdog_register_driver() to register watchdog device - Replace shutdown function with call to watchdog_stop_on_reboot() Signed-off-by: Guenter Roeck --- drivers/watchdog/atlas7_wdt.c | 61 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/drivers/watchdog/atlas7_wdt.c b/drivers/watchdog/atlas7_wdt.c index e170933aa0a8..79337d2a8a8e 100644 --- a/drivers/watchdog/atlas7_wdt.c +++ b/drivers/watchdog/atlas7_wdt.c @@ -125,78 +125,57 @@ static const struct of_device_id atlas7_wdt_ids[] = { {} }; +static void atlas7_clk_disable_unprepare(void *data) +{ + clk_disable_unprepare(data); +} + static int atlas7_wdt_probe(struct platform_device *pdev) { - struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; struct atlas7_wdog *wdt; struct clk *clk; int ret; - wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); if (!wdt) return -ENOMEM; wdt->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(wdt->base)) return PTR_ERR(wdt->base); - clk = of_clk_get(np, 0); + clk = devm_clk_get(dev, NULL); if (IS_ERR(clk)) return PTR_ERR(clk); ret = clk_prepare_enable(clk); if (ret) { - dev_err(&pdev->dev, "clk enable failed\n"); - goto err; + dev_err(dev, "clk enable failed\n"); + return ret; } + ret = devm_add_action_or_reset(dev, atlas7_clk_disable_unprepare, clk); + if (ret) + return ret; /* disable watchdog hardware */ writel(0, wdt->base + ATLAS7_WDT_CNT_CTRL); wdt->tick_rate = clk_get_rate(clk); - if (!wdt->tick_rate) { - ret = -EINVAL; - goto err1; - } + if (!wdt->tick_rate) + return -EINVAL; wdt->clk = clk; atlas7_wdd.min_timeout = 1; atlas7_wdd.max_timeout = UINT_MAX / wdt->tick_rate; - watchdog_init_timeout(&atlas7_wdd, 0, &pdev->dev); + watchdog_init_timeout(&atlas7_wdd, 0, dev); watchdog_set_nowayout(&atlas7_wdd, nowayout); watchdog_set_drvdata(&atlas7_wdd, wdt); platform_set_drvdata(pdev, &atlas7_wdd); - ret = watchdog_register_device(&atlas7_wdd); - if (ret) - goto err1; - - return 0; - -err1: - clk_disable_unprepare(clk); -err: - clk_put(clk); - return ret; -} - -static void atlas7_wdt_shutdown(struct platform_device *pdev) -{ - struct watchdog_device *wdd = platform_get_drvdata(pdev); - struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd); - - atlas7_wdt_disable(wdd); - clk_disable_unprepare(wdt->clk); -} - -static int atlas7_wdt_remove(struct platform_device *pdev) -{ - struct watchdog_device *wdd = platform_get_drvdata(pdev); - struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd); - - atlas7_wdt_shutdown(pdev); - clk_put(wdt->clk); - return 0; + watchdog_stop_on_reboot(&atlas7_wdd); + watchdog_stop_on_unregister(&atlas7_wdd); + return devm_watchdog_register_device(dev, &atlas7_wdd); } static int __maybe_unused atlas7_wdt_suspend(struct device *dev) @@ -234,8 +213,6 @@ static struct platform_driver atlas7_wdt_driver = { .of_match_table = atlas7_wdt_ids, }, .probe = atlas7_wdt_probe, - .remove = atlas7_wdt_remove, - .shutdown = atlas7_wdt_shutdown, }; module_platform_driver(atlas7_wdt_driver); -- 2.7.4