Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5119789yba; Wed, 10 Apr 2019 11:46:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTR4wPWjU6od6ZBhTmXmPZz7+USE1hkIoX+YFIFuU6oGZWjY8y3Q4WKm/yNiOIh/Mr4iJ9 X-Received: by 2002:a63:5854:: with SMTP id i20mr41499562pgm.171.1554921970707; Wed, 10 Apr 2019 11:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554921970; cv=none; d=google.com; s=arc-20160816; b=pK7ugSxw2/iXxj/TXFvwJy+iUe6QnvD2X2FtyNVZQVabZdkDXF805LLEHYwVbCvhSy 1VzoP0I73zidt4VmaVgm36YU/y4tDu/ubYehFiG6+z07bDdYOD1BaBCoFMiUZOdS7WtO ZC2ygoXCmfOSB+xA4sB7H17hhPi2mIreWIOLJJ+yRmwR+d0QAk/JPoGCWAdMggfd0OcG LTJvSS6+HNv2XnAZFxxei7aUsbsVwVEgNPJoInIyC0dPgbb+gPG4H0UW8LYZ9dgIOx67 EUse3mVXMPWei++yu9YT2tf52OHhcOfdr8Bj8jjzkOxgwsiX8w+ozYap2FmJ9Dr/gNtX 8bdA== 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=JFv/8qpijJBi/9fN4f4BgoRTl0I89T7cUIqnwNgfi5A=; b=B7DhZUKyL4T2rqhCXlbq6d63ProbPhgrLrzpdL6eBlk2GozFT7CC2N5QkUmcHjpIUf Zp09q5NSjZK9rhm36IUm3j0AT4FXipAF5fqG0EoFIexQJ4keY4lYSfQDbgSh+w53Xkcl r56h8YPsLCpOTcc1+SNl47djad94I+p5og3t7U+zqM5QvQtUOdfAaucfqhGVjpD/DzNc J5hZJs6U88JWKokP2qzTufFx+y/vpuc0qbCDJUo3nZ4iQFCAZT75PNyveFXJlr0zEBTP 8JTTZPWWvUg6Cfn73sT4YnwWJ7cLH0BZvfNa0a/1bKLAA07FhYz+Z5E3J04fHmq5XIsT os1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=cyKbWJwE; 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 d37si9347738pla.97.2019.04.10.11.45.54; Wed, 10 Apr 2019 11:46: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=cyKbWJwE; 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 S2387940AbfDJQ2f (ORCPT + 99 others); Wed, 10 Apr 2019 12:28:35 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41342 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387884AbfDJQ2c (ORCPT ); Wed, 10 Apr 2019 12:28:32 -0400 Received: by mail-pg1-f195.google.com with SMTP id f6so1856016pgs.8; Wed, 10 Apr 2019 09:28:31 -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=JFv/8qpijJBi/9fN4f4BgoRTl0I89T7cUIqnwNgfi5A=; b=cyKbWJwEIouqNYxadt+0H1pjEPe1zG8jT/lZkrFPingsqh2a8NK8jER/bUy6OGpqMy qFsV4+GNoq3P1g/C9HmzUEqL7GEdTPt1aJS2fP0ucYkoWzXzI6YfCKZlw8jF3KxkfOZJ gN5PCdHV2HcK4hvNIxNBmZpNI3e04PdeWB4ogeC4LWcIZG5IZRsvJffhRtciuE9nHV/w aty3VBCDQdPYRJ4pYON+p/Q3w5kwRKnbdpqmV0MVeMkeobzomEAEzx7opteuDiudH8b6 ee61GwOw9alfAs90DRGdIPNETqCcA6akyohfKbLErQXi600YEHERbkbawgcPorRFFq74 niWQ== 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=JFv/8qpijJBi/9fN4f4BgoRTl0I89T7cUIqnwNgfi5A=; b=VbH5nvc07wYlVKCoCAYa9tqQJ9XRMMyAF8/+u4OqaZHRd7+WGrKJ+GRvfA0NMpUFS0 eyjD8pjxtGv2QQTEEql3AxFO+Otr2Awif6ur6yxHxeIutKYunESwtsyyCALK0tmIyEP/ 0LJOMoREmaT332elcYvpUsNDsM0ovp2d2EYgxYAUEIPwopIE9LUBTJ3CUp/YWbqwQCGH YxsCITDP73MyPcKzqC1qip2xLhLqt4u9z4hgpEITe6NJ/vLMuA6cxDISHgiCnNfE+4pq oUEYYFIZDhXIn3jIrDxhK4rDLsBFoKN+TQNDiccGcDMCbZ5WF7lF8ddvCvJv2+bNUmwD lOmQ== X-Gm-Message-State: APjAAAVeDhWOKPIQMQ2kk9WJiV8T6oVF4Xz4I8Lsgvncrz9uFaIL6adB VhiWqLmE00cIfoGV+zLzAHE= X-Received: by 2002:a65:608a:: with SMTP id t10mr30773110pgu.125.1554913711421; Wed, 10 Apr 2019 09:28:31 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id n3sm63468609pfa.99.2019.04.10.09.28.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 09:28:30 -0700 (PDT) From: Guenter Roeck To: Wim Van Sebroeck Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Keguang Zhang Subject: [PATCH 17/22] watchdog: loongson1_wdt: Convert to use device managed functions and other improvements Date: Wed, 10 Apr 2019 09:27:58 -0700 Message-Id: <1554913683-25454-18-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 unnecessary braces around conditional return statements - 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: Keguang Zhang Signed-off-by: Guenter Roeck --- drivers/watchdog/loongson1_wdt.c | 48 ++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/watchdog/loongson1_wdt.c b/drivers/watchdog/loongson1_wdt.c index 1119634b5c87..d8075e2affa7 100644 --- a/drivers/watchdog/loongson1_wdt.c +++ b/drivers/watchdog/loongson1_wdt.c @@ -83,14 +83,20 @@ static const struct watchdog_ops ls1x_wdt_ops = { .set_timeout = ls1x_wdt_set_timeout, }; +static void ls1x_clk_disable_unprepare(void *data) +{ + clk_disable_unprepare(data); +} + static int ls1x_wdt_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct ls1x_wdt_drvdata *drvdata; struct watchdog_device *ls1x_wdt; unsigned long clk_rate; int err; - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); if (!drvdata) return -ENOMEM; @@ -98,21 +104,23 @@ static int ls1x_wdt_probe(struct platform_device *pdev) if (IS_ERR(drvdata->base)) return PTR_ERR(drvdata->base); - drvdata->clk = devm_clk_get(&pdev->dev, pdev->name); + drvdata->clk = devm_clk_get(dev, pdev->name); if (IS_ERR(drvdata->clk)) return PTR_ERR(drvdata->clk); err = clk_prepare_enable(drvdata->clk); if (err) { - dev_err(&pdev->dev, "clk enable failed\n"); + dev_err(dev, "clk enable failed\n"); return err; } + err = devm_add_action_or_reset(dev, ls1x_clk_disable_unprepare, + drvdata->clk); + if (err) + return err; clk_rate = clk_get_rate(drvdata->clk); - if (!clk_rate) { - err = -EINVAL; - goto err0; - } + if (!clk_rate) + return -EINVAL; drvdata->clk_rate = clk_rate; ls1x_wdt = &drvdata->wdt; @@ -121,41 +129,27 @@ static int ls1x_wdt_probe(struct platform_device *pdev) ls1x_wdt->timeout = DEFAULT_HEARTBEAT; ls1x_wdt->min_timeout = 1; ls1x_wdt->max_hw_heartbeat_ms = U32_MAX / clk_rate * 1000; - ls1x_wdt->parent = &pdev->dev; + ls1x_wdt->parent = dev; - watchdog_init_timeout(ls1x_wdt, heartbeat, &pdev->dev); + watchdog_init_timeout(ls1x_wdt, heartbeat, dev); watchdog_set_nowayout(ls1x_wdt, nowayout); watchdog_set_drvdata(ls1x_wdt, drvdata); - err = watchdog_register_device(&drvdata->wdt); + err = devm_watchdog_register_device(dev, &drvdata->wdt); if (err) { - dev_err(&pdev->dev, "failed to register watchdog device\n"); - goto err0; + dev_err(dev, "failed to register watchdog device\n"); + return err; } platform_set_drvdata(pdev, drvdata); - dev_info(&pdev->dev, "Loongson1 Watchdog driver registered\n"); - - return 0; -err0: - clk_disable_unprepare(drvdata->clk); - return err; -} - -static int ls1x_wdt_remove(struct platform_device *pdev) -{ - struct ls1x_wdt_drvdata *drvdata = platform_get_drvdata(pdev); - - watchdog_unregister_device(&drvdata->wdt); - clk_disable_unprepare(drvdata->clk); + dev_info(dev, "Loongson1 Watchdog driver registered\n"); return 0; } static struct platform_driver ls1x_wdt_driver = { .probe = ls1x_wdt_probe, - .remove = ls1x_wdt_remove, .driver = { .name = "ls1x-wdt", }, -- 2.7.4