Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp214142imb; Thu, 28 Feb 2019 21:39:35 -0800 (PST) X-Google-Smtp-Source: APXvYqzOFhNtGdTAhjNuzK3MkF9RU/8598rUV+JEwpPI3vHmUI+I0PyYCYLFgYpPOqfXFXAJNnIp X-Received: by 2002:a17:902:1027:: with SMTP id b36mr3615023pla.339.1551418774962; Thu, 28 Feb 2019 21:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551418774; cv=none; d=google.com; s=arc-20160816; b=vCLYBn1xBljahLlDayy8eX0JbLXJXA4uwWQ8OnpGV+yeLwm+e4m8tKA77l4L5fbQzx Uv8mpsMYpz6bbT1TxLS2eBjp1bOvpsXyirTrP9WeR3cHWgbYJ0B4avuTXFrk3cmK4UV3 oVREWBf5f1TX+r8WyGzdPJS/NuZNNJv8+yQJjnpT5eEKFTtPEXB6wvoWWeeowQWR25Sb mVma/JOkkGNiVOfQGsnSFuSyuN+U39CV8e7Y2Mkmv8QkSdgcZj4wStTGH/B3RNhKxix7 6xoM22WczgdjPeEeRRaZJZqAyq08egAjAP+dOsFQkb2TBxMRj5+77YaVcz+9Jnf4Iwz5 w/3Q== 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=vHCTbaZLtaKyLUTxsQ3Ez4tooEedYY2vUh07XCDQ3kM=; b=cUX+lHO/SdV+hH0hVlQwuMut8rzVW/X5dWBjLnZWTWysXrkE+rDqswPQD3Ui83SnM4 OeCv+dGUQ45tK7T31pp6ljN+dicrITt1qSsJJKQ/EiFixuNzAeCmbAd1jNFA6IlSx4YR shO4CvYTLUmmk2ooRobuU6KQ0YK3etGfrCgM9XK8mSmB8DgZjFKoNVIFeAubFaZQ6GEY SYAY0/HQLi1FAqhFkxXT5kn9+oTtcgTaRZl0N/Ojm1YG20EVT8fq1UxYzs29/08CY34R GbZadxBcD6/sliucXiP2qm7ShG5szlBwXTu9jH9mqkjjkhrYKFbRpk5pNLBelbpuyFWN eclA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b10si18505025plz.385.2019.02.28.21.39.19; Thu, 28 Feb 2019 21:39:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1732086AbfCAFiY (ORCPT + 99 others); Fri, 1 Mar 2019 00:38:24 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:42726 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731671AbfCAFiU (ORCPT ); Fri, 1 Mar 2019 00:38:20 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from parav@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Mar 2019 07:38:13 +0200 Received: from sw-mtx-036.mtx.labs.mlnx (sw-mtx-036.mtx.labs.mlnx [10.12.150.149]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x215brYa016903; Fri, 1 Mar 2019 07:38:11 +0200 From: Parav Pandit To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, michal.lkml@markovi.net, davem@davemloft.net, gregkh@linuxfoundation.org, jiri@mellanox.com Cc: parav@mellanox.com Subject: [RFC net-next 5/8] devlink: Add variant of devlink_register/unregister Date: Thu, 28 Feb 2019 23:37:49 -0600 Message-Id: <1551418672-12822-6-git-send-email-parav@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551418672-12822-1-git-send-email-parav@mellanox.com> References: <1551418672-12822-1-git-send-email-parav@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add variants of devlink_register and devlink_unregister which doesn't explicitly acquire/release devlink_mutex lock, but requires that caller hold the devlink_mutex lock. This is required to create child devlink devices while working on parent devlink device. Change-Id: I74417158144b28ff51ecfb2d1105c83ebefdf985 Signed-off-by: Parav Pandit --- include/net/devlink.h | 15 ++++++++++++++- net/core/devlink.c | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index ae5e0e6..9a067b1 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -545,7 +545,9 @@ static inline struct devlink *priv_to_devlink(void *priv) void devlink_init(struct devlink *devlink, const struct devlink_ops *ops); void devlink_cleanup(struct devlink *devlink); struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size); +void __devlink_register(struct devlink *devlink, struct device *dev); int devlink_register(struct devlink *devlink, struct device *dev); +void __devlink_unregister(struct devlink *devlink); void devlink_unregister(struct devlink *devlink); void devlink_free(struct devlink *devlink); int devlink_port_register(struct devlink *devlink, @@ -713,6 +715,7 @@ int devlink_health_report(struct devlink_health_reporter *reporter, static inline void devlink_init(struct devlink *devlink, const struct devlink_ops *ops) +{ } static inline void devlink_cleanup(struct devlink *devlink) @@ -725,11 +728,21 @@ static inline struct devlink *devlink_alloc(const struct devlink_ops *ops, return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL); } -static inline int devlink_register(struct devlink *devlink, struct device *dev) +static inline void __devlink_register(struct devlink *devlink, + struct device *dev) +{ +} + +static inline int devlink_register(struct devlink *devlink, + struct device *dev) { return 0; } +static inline void __devlink_unregister(struct devlink *devlink) +{ +} + static inline void devlink_unregister(struct devlink *devlink) { } diff --git a/net/core/devlink.c b/net/core/devlink.c index 25492c6..cfbad2c 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5262,22 +5262,49 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size) EXPORT_SYMBOL_GPL(devlink_alloc); /** - * devlink_register - Register devlink instance + * __devlink_register - Register devlink instance + * Caller must hold devlink_mutex. * * @devlink: devlink */ -int devlink_register(struct devlink *devlink, struct device *dev) +void __devlink_register(struct devlink *devlink, struct device *dev) { - mutex_lock(&devlink_mutex); + lockdep_assert_held(&devlink_mutex); devlink->dev = dev; list_add_tail(&devlink->list, &devlink_list); devlink_notify(devlink, DEVLINK_CMD_NEW); +} +EXPORT_SYMBOL_GPL(__devlink_register); + +/** + * devlink_register - Register devlink instance + * + * @devlink: devlink + */ +int devlink_register(struct devlink *devlink, struct device *dev) +{ + mutex_lock(&devlink_mutex); + __devlink_register(devlink, dev); mutex_unlock(&devlink_mutex); return 0; } EXPORT_SYMBOL_GPL(devlink_register); /** + * __devlink_unregister - Unregister devlink instance + * Caller must hold the devlink_mutex while invoking this API. + * + * @devlink: devlink + */ +void __devlink_unregister(struct devlink *devlink) +{ + lockdep_assert_held(&devlink_mutex); + devlink_notify(devlink, DEVLINK_CMD_DEL); + list_del(&devlink->list); +} +EXPORT_SYMBOL_GPL(__devlink_unregister); + +/** * devlink_unregister - Unregister devlink instance * * @devlink: devlink @@ -5285,8 +5312,7 @@ int devlink_register(struct devlink *devlink, struct device *dev) void devlink_unregister(struct devlink *devlink) { mutex_lock(&devlink_mutex); - devlink_notify(devlink, DEVLINK_CMD_DEL); - list_del(&devlink->list); + __devlink_unregister(devlink); mutex_unlock(&devlink_mutex); } EXPORT_SYMBOL_GPL(devlink_unregister); -- 1.8.3.1