Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp497937ybt; Fri, 10 Jul 2020 05:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydCzNQ3w1jJa+3fS+z8LMu8JfNBaE1hK2EJBaZPrbNY82bytTyC0WH3A1H8NWl1F95g3gN X-Received: by 2002:a50:d784:: with SMTP id w4mr17692937edi.34.1594384028983; Fri, 10 Jul 2020 05:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594384028; cv=none; d=google.com; s=arc-20160816; b=NY2uXBI12oC1pP0jP5ZfcVJH00Dr/qjG7oWR8F5xxR1CV100jy9O9FI/bvxoEg2U4Q umFcfXtK4iDH15PwWGT+T38ifGRuPFU0QFsxcMz/r8Jy8CM1JTYIxWwA9vFMMuh1wQbS j7ZQHVlMLsA6b0noDWzx0buJiYQ/x6Un0Yj/pPvlJe03obGAR7eP9/gUIy+RsODypuUE qRaPeYUowN1w47iTWHqc4epfAH67HbgKCqi5K2CPzyO+1HzF/i9HmIK019urB8biaBnc sPu4HTLKb7uDu9YwiVbf5LbaYZJx1k1PTA538cqWyNxZgkVwFMSeirBe1TzryYNHq8wj OrMQ== 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; bh=yaR332GSWVxypYkvi+Mn3KsxdiqqfGhTfox9GffnJAw=; b=WKoNjavgAJx60oImRwh9E7R7k8TxQnMkfElcufYDO/DYZTw1t5kJWt4kCJID+4w/Ij L/9uYo60TIRbubaKYQ2sPnYYOCzcBl2sGnebkPYjldk3uX1jRxGOZIlRAAH1MPdOUoqn 9lxhDXldsldW72pruYx1kSK+PXr7oAEMgMe/ESZnD0tLJ1+9kQY1eXVqyoQArPhRbHl0 XENYGkM6+0wyQODEgWdbbVguESW464qi34DP74zijF7uDRnwEsvff9EmByO5n7zMV4qk tWzn0M32j+FgSxCbeXVocJzfAKjjP1ROIiu1zD8ri3DVXJ1LNsKWdWHg0T//TrqIWjYR c+/A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si3882807edr.480.2020.07.10.05.26.46; Fri, 10 Jul 2020 05:27:08 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727927AbgGJMZ4 (ORCPT + 99 others); Fri, 10 Jul 2020 08:25:56 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:51770 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727060AbgGJMZz (ORCPT ); Fri, 10 Jul 2020 08:25:55 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 10 Jul 2020 15:25:48 +0300 Received: from dev-l-vrt-136.mtl.labs.mlnx (dev-l-vrt-136.mtl.labs.mlnx [10.234.136.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 06ACPmrN012383; Fri, 10 Jul 2020 15:25:48 +0300 Received: from dev-l-vrt-136.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7) with ESMTP id 06ACPmOo003369; Fri, 10 Jul 2020 15:25:48 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id 06ACPm1L003368; Fri, 10 Jul 2020 15:25:48 +0300 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski Cc: Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vladyslav Tarasiuk Subject: [PATCH net-next v3 1/7] devlink: Refactor devlink health reporter constructor Date: Fri, 10 Jul 2020 15:25:07 +0300 Message-Id: <1594383913-3295-2-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1594383913-3295-1-git-send-email-moshe@mellanox.com> References: <1594383913-3295-1-git-send-email-moshe@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladyslav Tarasiuk Prepare a common routine in devlink_health_reporter_create() for usage in similar functions for devlink port health reporters. Signed-off-by: Vladyslav Tarasiuk Reviewed-by: Moshe Shemesh Reviewed-by: Jiri Pirko --- net/core/devlink.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index 346d385..a203d35 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5321,6 +5321,31 @@ struct devlink_health_reporter { return NULL; } +static struct devlink_health_reporter * +__devlink_health_reporter_create(struct devlink *devlink, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv) +{ + struct devlink_health_reporter *reporter; + + if (WARN_ON(graceful_period && !ops->recover)) + return ERR_PTR(-EINVAL); + + reporter = kzalloc(sizeof(*reporter), GFP_KERNEL); + if (!reporter) + return ERR_PTR(-ENOMEM); + + reporter->priv = priv; + reporter->ops = ops; + reporter->devlink = devlink; + reporter->graceful_period = graceful_period; + reporter->auto_recover = !!ops->recover; + reporter->auto_dump = !!ops->dump; + mutex_init(&reporter->dump_lock); + refcount_set(&reporter->refcount, 1); + return reporter; +} + /** * devlink_health_reporter_create - create devlink health reporter * @@ -5342,25 +5367,11 @@ struct devlink_health_reporter * goto unlock; } - if (WARN_ON(graceful_period && !ops->recover)) { - reporter = ERR_PTR(-EINVAL); + reporter = __devlink_health_reporter_create(devlink, ops, + graceful_period, priv); + if (IS_ERR(reporter)) goto unlock; - } - - reporter = kzalloc(sizeof(*reporter), GFP_KERNEL); - if (!reporter) { - reporter = ERR_PTR(-ENOMEM); - goto unlock; - } - reporter->priv = priv; - reporter->ops = ops; - reporter->devlink = devlink; - reporter->graceful_period = graceful_period; - reporter->auto_recover = !!ops->recover; - reporter->auto_dump = !!ops->dump; - mutex_init(&reporter->dump_lock); - refcount_set(&reporter->refcount, 1); list_add_tail(&reporter->list, &devlink->reporter_list); unlock: mutex_unlock(&devlink->reporters_lock); -- 1.8.3.1