Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp452519pxb; Thu, 5 Nov 2020 04:41:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyk22Wz2OVcfOkKIQx38Da8Di2Bw5o646qi2tlg2F2tGzv8+8BzfOtyv9SnvNX44eDyVyeU X-Received: by 2002:a17:906:b110:: with SMTP id u16mr2063547ejy.55.1604580077526; Thu, 05 Nov 2020 04:41:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604580077; cv=none; d=google.com; s=arc-20160816; b=dhzFPXq6agK6H1F07Cx96rA8rwqaMjV3aSK2o8CvS5dNYiBIUKo1k/c0rglveKeTlC GSEX+zyy13oOrqF1WtjoZKy0tjrYn+KLMg2Y5olXWadAysIzkaNVKjS7SACq6y/z/Dk/ eXKVLjexaduejB8JsSuI4CAp2VHjZABLcKRJf3lCjcsA8VJbbgXqyyEGubN4rBogzq5B FoXa52F75OlrFVFrjyNgmoff0Cnp8k6UVQ4La1h8hR4RO81jAzNSPgLeRCr6Bnp9UHHR QM60LRs7yvql/1gV5GFflZT1NpL0Yw+L8YVKGt2QqLTwpMaVze+kELxY2a6D2X0sD8FW kbyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=I0RCOtxPn9Ru6Fpf//Dygmr9UAz4LZqqOE8K71R/0Xw=; b=soGJSI7j/3zSi1rXRwmp+tDK9tnNFMjDmmvFiTw0TR3slgWLUqVi8NflTpLGQTtJwg U2fAiMiwGRPVsKSLzUl75PPbPwYdBIclFMomgG/vaDD5ePh1Qug290yqhM9xj8EWew/b QEV3SOxEdkpS3IDTs5JjRmugOKDFIZTXeZMtYO0sIa0SzdjOh5P7N3gyYERtPxtP3kxp ZSBDRIN2bVVTqTDd311nQWHOJ3Z6VLNQcbnAyenQAzyTZTxKzP9SZgb490NNXIU75Wkz h0JNZlNF7hMLQZgf7M6mMNk17R4woBUVBVpuwE7HpuCDckicWafAyJT9i47WItpLupYz H0iQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si1010384edr.154.2020.11.05.04.40.55; Thu, 05 Nov 2020 04:41:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730534AbgKEMjQ (ORCPT + 99 others); Thu, 5 Nov 2020 07:39:16 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:7057 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726777AbgKEMjN (ORCPT ); Thu, 5 Nov 2020 07:39:13 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CRjkf5HJCzhYrj; Thu, 5 Nov 2020 20:39:06 +0800 (CST) Received: from huawei.com (10.175.112.208) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 5 Nov 2020 20:39:02 +0800 From: Wang Wensheng To: , , , CC: , Subject: [PATCH -next v3 2/2] watchdog: Clean up error handlings Date: Thu, 5 Nov 2020 12:38:48 +0000 Message-ID: <20201105123848.93735-2-wangwensheng4@huawei.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20201105123848.93735-1-wangwensheng4@huawei.com> References: <20201105123848.93735-1-wangwensheng4@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.208] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clean up the repeated error handling process in function __watchdog_register_device(). Signed-off-by: Wang Wensheng --- drivers/watchdog/watchdog_core.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 945ab38b14b8..4fa54a620ccd 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -252,10 +252,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd) wdd->id = id; ret = watchdog_dev_register(wdd); - if (ret) { - ida_simple_remove(&watchdog_ida, id); - return ret; - } + if (ret) + goto id_remove; } /* Module parameter to force watchdog policy on reboot. */ @@ -270,9 +268,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd) if (!wdd->ops->stop) { pr_err("watchdog%d: Cannot support stop_on_reboot\n", wdd->id); - watchdog_dev_unregister(wdd); - ida_simple_remove(&watchdog_ida, id); - return -EINVAL; + ret = -EINVAL; + goto dev_unregister; } wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; @@ -280,9 +277,7 @@ static int __watchdog_register_device(struct watchdog_device *wdd) if (ret) { pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", wdd->id, ret); - watchdog_dev_unregister(wdd); - ida_simple_remove(&watchdog_ida, id); - return ret; + goto dev_unregister; } } @@ -296,6 +291,13 @@ static int __watchdog_register_device(struct watchdog_device *wdd) } return 0; + +dev_unregister: + watchdog_dev_unregister(wdd); +id_remove: + ida_simple_remove(&watchdog_ida, id); + + return ret; } /** -- 2.25.0