Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1555777ybt; Thu, 2 Jul 2020 08:13:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMfBAcmzpa5ApGw+jNvqB3f6+f7Ow9IpkNoVoCw81VLlGPSopxBt5KGzlj4JbIGAngaS7T X-Received: by 2002:a50:9b0b:: with SMTP id o11mr36726164edi.22.1593702809606; Thu, 02 Jul 2020 08:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593702809; cv=none; d=google.com; s=arc-20160816; b=z5Z68B8WLlAq9waoJcMqa3Qpf77pN59sPj9bwP+/7pzZlSvG6i8ajXPNllniDzwk5l /gpojaHBsv24da9TT093Ya6FFaeoCX6wC9Rrjh6uifo65J81ztkpHTVfKk1ioRwKJYUq G8helpMz6R9Wrf6rioy0WZGUTF8OsWG6IbcvwO62bep7oPIn1aDrJ1SgZdcKgsy2GAf+ BqkRxAbDfNxYn99iQUBXDj+3EAy3sMhj+l7QlOtreYXA49wy//gkuOj1oqQ/1QysGwnT 2UPM/maPEg9wie/EG5/XBfskERKDP+O2pRnBY2RCmFZX7lRFWv9ePjpQLTdy9ToxeFTu uFtQ== 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=M6La8GOOwV8fe/vZSvdKpQTwPIcimU0uAf4dK5JEW71KIJiN7Foc47QHldwRVgb44z KLnIMlvSy56ekejRThuF1lMB3oWF5qr2AyYJg1iz4bm3zUD0ezUq55E+VgtsV2YJfYHk y6rdDVPb2XTz/Kg29CX3Y7qKCcZGrKU/Iaf+8eOGCPFk+/A1FV1w8OoNElNtAABkBvvE StN6jhwf7PARHx9kik7RpD/lLctpsYecDcuUdBFYrAVmdvjN/JrrPK3i/VG8xxkVTMrx fNFMXiqbZPSYsPKh3C3ys2ucw59SMoNXSzIh8pP2dclaDMkFSNOZIhwAW9cJbSbtppDN jFqg== 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 dk6si6013541ejb.129.2020.07.02.08.13.06; Thu, 02 Jul 2020 08:13:29 -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 S1729585AbgGBPJM (ORCPT + 99 others); Thu, 2 Jul 2020 11:09:12 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:39728 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726117AbgGBPJL (ORCPT ); Thu, 2 Jul 2020 11:09:11 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 2 Jul 2020 18:09:08 +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 062F98i9020256; Thu, 2 Jul 2020 18:09:08 +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 062F98cp015405; Thu, 2 Jul 2020 18:09:08 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id 062F98WP015404; Thu, 2 Jul 2020 18:09:08 +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 1/7] devlink: Refactor devlink health reporter constructor Date: Thu, 2 Jul 2020 18:08:07 +0300 Message-Id: <1593702493-15323-2-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1593702493-15323-1-git-send-email-moshe@mellanox.com> References: <1593702493-15323-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