Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp690823pxj; Fri, 11 Jun 2021 09:03:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUAjo/jipxi6WRyy/M3FeBynJa0hzsCw8ckg5jZugP5EcmI3tC+bPmoFWfQZTh3OeRxHmm X-Received: by 2002:a17:907:2648:: with SMTP id ar8mr4288370ejc.521.1623427433549; Fri, 11 Jun 2021 09:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623427433; cv=none; d=google.com; s=arc-20160816; b=B1Pq3cfX/mqusaVPEsunkppTQzYVlyJuYqTj/c762rlVDkrGL8BTT41PrWoRapWfC9 nDI2W3cVi1RQ9xVbTO9lA3e98ZBVhS/NYlhgdU5VQfxJIp10866RHj2JWEpbOBTDQmIU 89SgKH+qoaXOTe5MbWziUlI9hve5S1YaK3W4mp0uzDIndyZ7OXzKQuxqv6cnTv6xUIUs 5tZxicVrAcJ/9jvtfO+IOul30SlIWwmOCzJpezRjtfXquQf5FSzjm8k8PsrPmz49NBT4 zpr5eVaZxnAckR/1JjoE8jGuTxgejHrHhSwSPDolvAB2ez8b4sw6qvC9UfXvau/MC4z8 JxLQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EvkBmUF2nfADNbKcM35Z7PT7X0qdNa/eWhL1k0ATCaQ=; b=j5CDnT7UWlHFKb6Jz0enf6WJnmWmOoSRSCn1OzSHFV5ybFnJ2/vUmnTAMuLckDCta2 3gk9FHqBehoh5lopg3ts/EJ8g5c+SWCVGaFHjhqtGLJXZlHMGl9X2Ab1CCR/RoSjsxim cMfOAw9okYyPooJ476pP59UCAwBYPZW9fwkdefp/LrnoDSPoNUAeshYoW7aEm1PqqJKt pOQaOqyPrs1rmD0HBdQhfyHg7HhbaVxhNIWSCPD6RkkaaeEm90ZH5TvUUX3zr9EIMCrt SorlXrSS7MeNVZGaGBLMgCMk5G8i/X5y9yODhrtbsSAd5CJ8O4GAe5YtBsbSCGkkoIBx rGaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VB2kjSmZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx16si5263065edb.256.2021.06.11.09.03.24; Fri, 11 Jun 2021 09:03:53 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VB2kjSmZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbhFKQC7 (ORCPT + 99 others); Fri, 11 Jun 2021 12:02:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:38546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbhFKQCs (ORCPT ); Fri, 11 Jun 2021 12:02:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CC86361400; Fri, 11 Jun 2021 16:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623427250; bh=nQJrnyUptPppe56TF1U2FI5YFtqG7oMgx9SHiNklliE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VB2kjSmZD0tHOhLungvFgb4F+WlkZdKZ96HHovUZTnyoSrAtH4oQF8yof6EVDuBRl jYpwc3xzQtWV27B5fS823wI7XlU1zenzWC2iCyvlgueErSr1Sxw5G5HUXIioG4lv6u j9hG13iCPLjOKd6AItaAIwqyEuanW4nw0Hd3QUrrympKiSCW4YOhgqND6K9WNHlZrl Pm3liUkbPgN+pgCukdb8fN7KEVBoSW/0g9eAwkAd7/4MJn/ROrICqOkwZzWLuC2z4W DrrknwsZW2yehciYFvhyQpddSkKDPAWT4yiQhAP3DMWzYTw+HKcWxzWfyeim5PEO4m wD00LLgvxHjyg== From: Leon Romanovsky To: Doug Ledford , Jason Gunthorpe Cc: Greg KH , Kees Cook , Nathan Chancellor , Leon Romanovsky , Adit Ranadive , Ariel Elior , Christian Benvenuti , clang-built-linux@googlegroups.com, Dennis Dalessandro , Devesh Sharma , Gal Pressman , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michal Kalderon , Mike Marciniszyn , Mustafa Ismail , Naresh Kumar PBS , Nelson Escobar , Nick Desaulniers , Potnuri Bharat Teja , Selvin Xavier , Shiraz Saleem , VMware PV-Drivers , Yishai Hadas , Zhu Yanjun Subject: [PATCH rdma-next v2 04/15] RDMA/core: Split gid_attrs related sysfs from add_port() Date: Fri, 11 Jun 2021 19:00:23 +0300 Message-Id: <1c9434111b6770a7aef0e644a88a16eee7e325b8.1623427137.git.leonro@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe The gid_attrs directory is a dedicated kobj nested under the port, construct/destruct it with its own pair of functions for understandability. This is much more readable than having it weirdly inlined out of order into the add_port() function. Signed-off-by: Jason Gunthorpe Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/sysfs.c | 160 ++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 71 deletions(-) diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c index 114fecda9764..d2a089a6f666 100644 --- a/drivers/infiniband/core/sysfs.c +++ b/drivers/infiniband/core/sysfs.c @@ -1178,6 +1178,85 @@ struct rdma_hw_stats *ib_get_hw_stats_port(struct ib_device *ibdev, return ibdev->port_data[port_num].sysfs->hw_stats_data->stats; } +/* + * Create the sysfs: + * ibp0s9/ports/XX/gid_attrs/{ndevs,types}/YYY + * YYY is the gid table index in decimal + */ +static int setup_gid_attrs(struct ib_port *port, + const struct ib_port_attr *attr) +{ + struct gid_attr_group *gid_attr_group; + int ret; + int i; + + gid_attr_group = kzalloc(sizeof(*gid_attr_group), GFP_KERNEL); + if (!gid_attr_group) + return -ENOMEM; + + gid_attr_group->port = port; + ret = kobject_init_and_add(&gid_attr_group->kobj, &gid_attr_type, + &port->kobj, "gid_attrs"); + if (ret) + goto err_put_gid_attrs; + + gid_attr_group->ndev.name = "ndevs"; + gid_attr_group->ndev.attrs = + alloc_group_attrs(show_port_gid_attr_ndev, attr->gid_tbl_len); + if (!gid_attr_group->ndev.attrs) { + ret = -ENOMEM; + goto err_put_gid_attrs; + } + + ret = sysfs_create_group(&gid_attr_group->kobj, &gid_attr_group->ndev); + if (ret) + goto err_free_gid_ndev; + + gid_attr_group->type.name = "types"; + gid_attr_group->type.attrs = alloc_group_attrs( + show_port_gid_attr_gid_type, attr->gid_tbl_len); + if (!gid_attr_group->type.attrs) { + ret = -ENOMEM; + goto err_remove_gid_ndev; + } + + ret = sysfs_create_group(&gid_attr_group->kobj, &gid_attr_group->type); + if (ret) + goto err_free_gid_type; + + port->gid_attr_group = gid_attr_group; + return 0; + +err_free_gid_type: + for (i = 0; i < attr->gid_tbl_len; ++i) + kfree(gid_attr_group->type.attrs[i]); + + kfree(gid_attr_group->type.attrs); + gid_attr_group->type.attrs = NULL; +err_remove_gid_ndev: + sysfs_remove_group(&gid_attr_group->kobj, &gid_attr_group->ndev); +err_free_gid_ndev: + for (i = 0; i < attr->gid_tbl_len; ++i) + kfree(gid_attr_group->ndev.attrs[i]); + + kfree(gid_attr_group->ndev.attrs); + gid_attr_group->ndev.attrs = NULL; +err_put_gid_attrs: + kobject_put(&gid_attr_group->kobj); + return ret; +} + +static void destroy_gid_attrs(struct ib_port *port) +{ + struct gid_attr_group *gid_attr_group = port->gid_attr_group; + + sysfs_remove_group(&gid_attr_group->kobj, + &gid_attr_group->ndev); + sysfs_remove_group(&gid_attr_group->kobj, + &gid_attr_group->type); + kobject_put(&gid_attr_group->kobj); +} + static int add_port(struct ib_core_device *coredev, int port_num) { struct ib_device *device = rdma_device_to_ibdev(&coredev->dev); @@ -1204,23 +1283,11 @@ static int add_port(struct ib_core_device *coredev, int port_num) if (ret) goto err_put; - p->gid_attr_group = kzalloc(sizeof(*p->gid_attr_group), GFP_KERNEL); - if (!p->gid_attr_group) { - ret = -ENOMEM; - goto err_put; - } - - p->gid_attr_group->port = p; - ret = kobject_init_and_add(&p->gid_attr_group->kobj, &gid_attr_type, - &p->kobj, "gid_attrs"); - if (ret) - goto err_put_gid_attrs; - if (device->ops.process_mad && is_full_dev) { p->pma_table = get_counter_table(device, port_num); ret = sysfs_create_group(&p->kobj, p->pma_table); if (ret) - goto err_put_gid_attrs; + goto err_put; } p->gid_group.name = "gids"; @@ -1234,37 +1301,11 @@ static int add_port(struct ib_core_device *coredev, int port_num) if (ret) goto err_free_gid; - p->gid_attr_group->ndev.name = "ndevs"; - p->gid_attr_group->ndev.attrs = alloc_group_attrs(show_port_gid_attr_ndev, - attr.gid_tbl_len); - if (!p->gid_attr_group->ndev.attrs) { - ret = -ENOMEM; - goto err_remove_gid; - } - - ret = sysfs_create_group(&p->gid_attr_group->kobj, - &p->gid_attr_group->ndev); - if (ret) - goto err_free_gid_ndev; - - p->gid_attr_group->type.name = "types"; - p->gid_attr_group->type.attrs = alloc_group_attrs(show_port_gid_attr_gid_type, - attr.gid_tbl_len); - if (!p->gid_attr_group->type.attrs) { - ret = -ENOMEM; - goto err_remove_gid_ndev; - } - - ret = sysfs_create_group(&p->gid_attr_group->kobj, - &p->gid_attr_group->type); - if (ret) - goto err_free_gid_type; - if (attr.pkey_tbl_len) { p->pkey_group = kzalloc(sizeof(*p->pkey_group), GFP_KERNEL); if (!p->pkey_group) { ret = -ENOMEM; - goto err_remove_gid_type; + goto err_remove_gid; } p->pkey_group->name = "pkeys"; @@ -1290,11 +1331,14 @@ static int add_port(struct ib_core_device *coredev, int port_num) if (ret && ret != -EOPNOTSUPP) goto err_remove_pkey; } + ret = setup_gid_attrs(p, &attr); + if (ret) + goto err_remove_stats; if (device->ops.init_port && is_full_dev) { ret = device->ops.init_port(device, port_num, &p->kobj); if (ret) - goto err_remove_stats; + goto err_remove_gid_attrs; } list_add_tail(&p->kobj.entry, &coredev->port_list); @@ -1304,6 +1348,9 @@ static int add_port(struct ib_core_device *coredev, int port_num) kobject_uevent(&p->kobj, KOBJ_ADD); return 0; +err_remove_gid_attrs: + destroy_gid_attrs(p); + err_remove_stats: destroy_hw_port_stats(p); @@ -1323,28 +1370,6 @@ static int add_port(struct ib_core_device *coredev, int port_num) err_free_pkey_group: kfree(p->pkey_group); -err_remove_gid_type: - sysfs_remove_group(&p->gid_attr_group->kobj, - &p->gid_attr_group->type); - -err_free_gid_type: - for (i = 0; i < attr.gid_tbl_len; ++i) - kfree(p->gid_attr_group->type.attrs[i]); - - kfree(p->gid_attr_group->type.attrs); - p->gid_attr_group->type.attrs = NULL; - -err_remove_gid_ndev: - sysfs_remove_group(&p->gid_attr_group->kobj, - &p->gid_attr_group->ndev); - -err_free_gid_ndev: - for (i = 0; i < attr.gid_tbl_len; ++i) - kfree(p->gid_attr_group->ndev.attrs[i]); - - kfree(p->gid_attr_group->ndev.attrs); - p->gid_attr_group->ndev.attrs = NULL; - err_remove_gid: sysfs_remove_group(&p->kobj, &p->gid_group); @@ -1359,9 +1384,6 @@ static int add_port(struct ib_core_device *coredev, int port_num) if (p->pma_table) sysfs_remove_group(&p->kobj, p->pma_table); -err_put_gid_attrs: - kobject_put(&p->gid_attr_group->kobj); - err_put: kobject_put(&p->kobj); return ret; @@ -1498,11 +1520,7 @@ void ib_free_port_attrs(struct ib_core_device *coredev) if (port->pkey_group) sysfs_remove_group(p, port->pkey_group); sysfs_remove_group(p, &port->gid_group); - sysfs_remove_group(&port->gid_attr_group->kobj, - &port->gid_attr_group->ndev); - sysfs_remove_group(&port->gid_attr_group->kobj, - &port->gid_attr_group->type); - kobject_put(&port->gid_attr_group->kobj); + destroy_gid_attrs(port); kobject_put(p); } -- 2.31.1