Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp297534pxb; Mon, 2 Nov 2020 22:57:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcQSqyxLGrDsieVl3Uvuq2dR9/cvTKlh6mk90Lh5qdIXHJPavf55udb/n26fiHPa57+pWc X-Received: by 2002:a05:6402:754:: with SMTP id p20mr20381894edy.109.1604386626601; Mon, 02 Nov 2020 22:57:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604386626; cv=none; d=google.com; s=arc-20160816; b=qdy20OQX/95XfDnGPL8Wuxm+OpLvjbcQNGciG2ap8hYJ9pFM+SgdZe12GEGhfM4RTD t8cOLcZDwpFUnHdxRV0wAIPu9QBNigZnXJo6NKeMhwDmbkFr74paJAFY8+MqyfN7gyC2 ZvzRFqdFVkIYXf1uRwov9m6YmsZL0zP+imNMmdjW75uh2tzfoAVreUN8Sz+Q1lF08NaO 5LW6WPex6h2knFCTUPgrbusz05Q6MgZthzj0XIjhAsLylL+j2nKynb/ZRUbpvg12hxfI cQjYqxrKgIcx9uAKg6LFHOxmNsZm90f2ZaXHmuVNOY7SZ/r0kiqvU/ptcCywxOfv4m8w FhUQ== 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 :message-id:date:subject:cc:to:from; bh=l4zFBgZqlRMQw4l78fouRGCuJ/e0jeP1atlfUXthKcU=; b=Pj0FjO9BPxchJi8Kb0rhgibrNkuV8rOVeIy6xdKghkwQAvws2w8BBA37usfgE+DiXS Q5LJMf+aAO4YU2Sef9foh/mtvN6aHJK2lLk40RHQ+SULCua//dya13XY71OxK6F7+G84 Dj1/oty9ldbiMXGtRR7dZrIUmxX8u9R7lD60tvv42QiiqhFKMyS7+XFTqTzsR+2aYE4q fOE1ZXPlu+Necndv1l61lxh0YKqa6t7aegLuHPdsL4jVRDN6P39dAjhPdOGr6KmTsfld 8XmACQJjYP0QN/fKn0N+taJZACg7tL6B3GQ3Acn4xAUdPV8CwhVzz9r4P424m7t7Ae7W +7sQ== 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 ci2si4645744ejc.211.2020.11.02.22.56.44; Mon, 02 Nov 2020 22:57:06 -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 S1727628AbgKCGxB (ORCPT + 99 others); Tue, 3 Nov 2020 01:53:01 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:7405 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727794AbgKCGxB (ORCPT ); Tue, 3 Nov 2020 01:53:01 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CQL7l2Db1z6xy6; Tue, 3 Nov 2020 14:52:35 +0800 (CST) Received: from huawei.com (10.175.112.208) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 3 Nov 2020 14:52:27 +0800 From: Wang Wensheng To: , , , CC: , Subject: [PATCH -next v2 1/2] watchdog: Clean up error handlings of __watchdog_register_device Date: Tue, 3 Nov 2020 06:52:16 +0000 Message-ID: <20201103065217.67876-1-wangwensheng4@huawei.com> X-Mailer: git-send-email 2.25.0 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 Signed-off-by: Wang Wensheng --- drivers/watchdog/watchdog_core.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 423844757812..c73871f41142 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. */ @@ -273,9 +271,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; } } @@ -289,6 +285,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