Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1989728ybt; Thu, 2 Jul 2020 20:29:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2kurJV8aJ3rYLZjla4aRnwZrCCzX3poMF6QB3nRSg7j0jWHej2fWqx8dCJCp6SHaTfj8a X-Received: by 2002:a50:f392:: with SMTP id g18mr15989745edm.151.1593746946100; Thu, 02 Jul 2020 20:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593746946; cv=none; d=google.com; s=arc-20160816; b=PzlWO8CiOd9d0JnGzuXw7WDBACSrXGgCGscPUVkURWIxV6rS2oo+rM+h/3vl8lnKjn y5k9RT98H99QpH9263CEfiV5oIUNSK4LbVsvp/k9fEG7xSniOKE8OGloP0GMO+w9o/Ee +qIzld5a2z05c/81wI98BgMATOPxJcX9aa8MAhQ3iUMf3cWPJ5Ukhk5XjENUbkg8yjgD PwedttJdyl0hRrK7jh/uE3Y4sy250RF8steJf2cRqhx3YaQFWENG9biNQlbUAJzXZ2Wr YE6BClAOWuCHI4vGOb2xQN24JI9+AMgiImJun1UCoONLibazGvQaIPagqVK+sEzdsZJd Ckug== 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=KTOJkrugw6bmRchWkjBQ/rbcc46TOssws1ncT3fZT1I=; b=Jdbrkr7DXcqHBBp5DbWJzUv9cqvmdjVd5+/J0row7S1OSGn6k2IhNxWR/rjuFUmOyO OE6lytQqgZ7c/aT1ub8pPO80nof5aFGp6Lwcilh1D1quRSMzGKi1flc0kqOywe7HX7xg cbk96M+1Cl0NN8EyumTa8sq0moTiwwTaDV9QGIp/jnpeVQgjjRI80buN2VlGZVMkIh65 AV93rxU7bxTCNLX3eUiRYOzXDU/Atm+zCeN6gmKmO2oTT0OBmdHhSZAnE3MiTTxQxnzQ ty3WL/7GpgCDgKp8u7MoTtAXaK3cVf8U+JkwIwJwcEdd+RnpiyOYOEgHM329fK9sg9/7 q7tw== 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 dn14si2417342ejc.697.2020.07.02.20.28.42; Thu, 02 Jul 2020 20:29:06 -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 S1726285AbgGCD20 (ORCPT + 99 others); Thu, 2 Jul 2020 23:28:26 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:33601 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726122AbgGCD2V (ORCPT ); Thu, 2 Jul 2020 23:28:21 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 3 Jul 2020 06:28:14 +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 0633SExG006780; Fri, 3 Jul 2020 06:28:14 +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 0633SEbi006656; Fri, 3 Jul 2020 06:28:14 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id 0633SE74006655; Fri, 3 Jul 2020 06:28:14 +0300 From: Moshe Shemesh To: "David S. Miller" Cc: Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vladyslav Tarasiuk Subject: [PATCH net-next v2 1/7] devlink: Refactor devlink health reporter constructor Date: Fri, 3 Jul 2020 06:27:32 +0300 Message-Id: <1593746858-6548-2-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1593746858-6548-1-git-send-email-moshe@mellanox.com> References: <1593746858-6548-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 6ae3680..dfd7fe2 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5295,6 +5295,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 * @@ -5316,25 +5341,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