Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp737451lqt; Tue, 19 Mar 2024 02:10:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtuVB2WixooU9Mqn2Kfl12A1uy2IXBjwq79WJTeqAyBaNX01jOlcoTNAhHKlJc/qfS/2NZWbyM9Nci8aS7/TT5VQ+1658aSrFUbVRDLw== X-Google-Smtp-Source: AGHT+IHUmSK1v3YLGZ0v8UxnEiVi6KL0+EBrYPKRUnw2dziJQ8TfglVhc6oRwq3QdfMf+drDdYJm X-Received: by 2002:a05:6358:c015:b0:17e:7c4b:bb56 with SMTP id kv21-20020a056358c01500b0017e7c4bbb56mr2309735rwc.15.1710839433671; Tue, 19 Mar 2024 02:10:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710839433; cv=pass; d=google.com; s=arc-20160816; b=xJPT8nr927kGLnuXL7oQvESBmi/8yfJEWy1vYoaAEXi/P/BguhlFugQ508vSi1JK7V WYJF1miS2z8yB9g87KYOBbuo/nRxxg//ccvpyjDVwhebGS9WBPWGA36hX0nAjG+sBG/R u2K0ueRlVl9E1DgRc+avzf6XveiO0MGbDrG+uUv/zSWhGJMWAeD/kdrpXfuP6t5h98vc CSoVr//DsZkPRcMnnZoqW5LcUwa/ip5DRf1bhLrocVS7lhH/KQzKb8lvhHRwC+75mQFu gXmkRZwPZXIK+8LRdla8yyH2meym6+Y+nSa2XlxkbvhW1cDajLpdfWTpihXgWzSSA6Il ZHeg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=fWbPYIc2yreZZU4F6NEHsTtZafoo5/fHquHKdIa0meg=; fh=o7HWHK/8NwNa7FZDO8MC4JQdCT7Pafz9ZSIqUw6YShk=; b=VlvqxmjW939oMK4VHzQajEpzZ62gEBaXAQ7oPm1o/d4vUXXxQEbrwjahiflpRGxIGu cyIt8ScN1qRFeYWKM2Nb8H41qMsFG4it1s9Ecv2DRWgb3J02e3A+/oY1vqvTCBGtbDZQ uzD/lrkTgbydi0YZdxRaLw2G06QQ/kHLv7Y2x5zsUIfhmfghNzkew8Yg2CRrOY0p1YJa NMD/l+nlL5EQY2xvvx8dZi2Jhq65EnjgZrJ3ibBYEj4gZGbZRMJjPlriuayaCNHTmyQd inUFkqsAp17N+69PUY+dQE1CNMOglElXCmLnxUYVsWiCVX2T0Hyoy/3NYwQZRO/mOCtt VkHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-107285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107285-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e11-20020a65478b000000b005e19d15689bsi9887794pgs.819.2024.03.19.02.10.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 02:10:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-107285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107285-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 718C5B20C3B for ; Tue, 19 Mar 2024 09:10:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E02F37C6D4; Tue, 19 Mar 2024 09:09:53 +0000 (UTC) Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D9717C090; Tue, 19 Mar 2024 09:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710839393; cv=none; b=lnrzWZ64ZZy/wUQp1xbJo250mQsucfBlMGTO7oTjdSiSXipeN1czsAHR+dhEiQAJ0Q8Fov3mq/vCSCRqrQaDJGBU3Dpah3stdYxhqr+wHxkoD8VbZ5zOszLqujJ7YqC8CDqBM+8Yq8hvlxUwug98N+F8jLiUCbJ7LaxwDJ+Gdjw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710839393; c=relaxed/simple; bh=EtRYh4nV23koP1b34l5lWPqF+hq36pBImX3IxMAQF2Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KMP9akXTpnSwBYpzB0X/UWxIWXgOTPwZCiuTLkG5O8RpfGtZUu1uNuxE+/UfwUCnlqHeHd4N2/KcN+iaVcakY6zhpxGSpI6PX1njaK1TWPJzEyCTLROvHgaPQ/3U8ZAg5TZBi40SYBDuSd7PVBEDzxUn3ui7Nzc8JfyFDMZwFVw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5658082d2c4so6665555a12.1; Tue, 19 Mar 2024 02:09:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710839390; x=1711444190; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fWbPYIc2yreZZU4F6NEHsTtZafoo5/fHquHKdIa0meg=; b=a8NHquA82k4IPFrcAtVJHWyAE5UnHcTNVlNfax6HtTWwS5KqeIvyOMqyzrtJrWaNy5 Cw6u1Frx3IfeLt4HuZ0OrZFBpDzHp/K718Bj0KesV6PcNb6vDmUiO4c7YhtE4lBaouBZ WO8dyBeYF7f9Q95AAZFlTBVmZKStkos/Lw1TrNB2YXUwAP6OiIDrwxyIb6YyxHZ7ap+L ibbazkaKBr4JG4xVM6f7bBBmBbRhCmcEWvOdHE8rCJil4KRTaOpAH9YCqi/cneLHfnOR fa5GjeB5WNuTpZwAzW+p2HJMWU4jjy8RPFFXpHYbvXExxsNpi2h4tjBoYERwF7ZJbOzP D63A== X-Forwarded-Encrypted: i=1; AJvYcCWpubn5Zhp5nHCTBvW8yMZ4mf3p4R6ZyglUakG2OIhR7GYETU0FFjprKDZdJGDUVE/EJgqb/gnO6ab7n7LfPbywwuSM0MjsQXe87dD5juy0yvDmkPcIeJ2SE6WRnsygyswU5UE7DJn69A== X-Gm-Message-State: AOJu0YxGqM+MmCu5LSqvdZ65pX54FTu1qPYK1GlzWetpmhftXsXqUrfz e94TWMBY6BIx3sISeovj6JR5J2uWFGEOpO8vLDRdSJxk0i/ChXKW X-Received: by 2002:a17:907:724f:b0:a46:70d1:dda6 with SMTP id ds15-20020a170907724f00b00a4670d1dda6mr10642514ejc.28.1710839389806; Tue, 19 Mar 2024 02:09:49 -0700 (PDT) Received: from localhost (fwdproxy-lla-003.fbsv.net. [2a03:2880:30ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id z10-20020a170906714a00b00a46c39e6a47sm1846660ejj.148.2024.03.19.02.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 02:09:49 -0700 (PDT) From: Breno Leitao To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky Cc: kuba@kernel.org, keescook@chromium.org, linux-rdma@vger.kernel.org (open list:HFI1 DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4] IB/hfi1: allocate dummy net_device dynamically Date: Tue, 19 Mar 2024 02:09:43 -0700 Message-ID: <20240319090944.2021309-1-leitao@debian.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from struct hfi1_netdev_rx by converting it into a pointer. Then use the leverage alloc_netdev() to allocate the net_device object at hfi1_alloc_rx(). [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao Acked-by: Dennis Dalessandro --- Changelog v2: * Free struct hfi1_netdev_rx allocation if alloc_netdev() fails * Pass zero as the private size for alloc_netdev(). * Remove wrong reference for iwl in the comments v3: * Re-worded the comment, by removing the first paragraph. v4: * Fix the changelog format --- drivers/infiniband/hw/hfi1/netdev.h | 2 +- drivers/infiniband/hw/hfi1/netdev_rx.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/netdev.h b/drivers/infiniband/hw/hfi1/netdev.h index 8aa074670a9c..07c8f77c9181 100644 --- a/drivers/infiniband/hw/hfi1/netdev.h +++ b/drivers/infiniband/hw/hfi1/netdev.h @@ -49,7 +49,7 @@ struct hfi1_netdev_rxq { * When 0 receive queues will be freed. */ struct hfi1_netdev_rx { - struct net_device rx_napi; + struct net_device *rx_napi; struct hfi1_devdata *dd; struct hfi1_netdev_rxq *rxq; int num_rx_q; diff --git a/drivers/infiniband/hw/hfi1/netdev_rx.c b/drivers/infiniband/hw/hfi1/netdev_rx.c index 720d4c85c9c9..cd6e78e257ef 100644 --- a/drivers/infiniband/hw/hfi1/netdev_rx.c +++ b/drivers/infiniband/hw/hfi1/netdev_rx.c @@ -188,7 +188,7 @@ static int hfi1_netdev_rxq_init(struct hfi1_netdev_rx *rx) int i; int rc; struct hfi1_devdata *dd = rx->dd; - struct net_device *dev = &rx->rx_napi; + struct net_device *dev = rx->rx_napi; rx->num_rx_q = dd->num_netdev_contexts; rx->rxq = kcalloc_node(rx->num_rx_q, sizeof(*rx->rxq), @@ -360,7 +360,12 @@ int hfi1_alloc_rx(struct hfi1_devdata *dd) if (!rx) return -ENOMEM; rx->dd = dd; - init_dummy_netdev(&rx->rx_napi); + rx->rx_napi = alloc_netdev(0, "dummy", NET_NAME_UNKNOWN, + init_dummy_netdev); + if (!rx->rx_napi) { + kfree(rx); + return -ENOMEM; + } xa_init(&rx->dev_tbl); atomic_set(&rx->enabled, 0); @@ -374,6 +379,7 @@ void hfi1_free_rx(struct hfi1_devdata *dd) { if (dd->netdev_rx) { dd_dev_info(dd, "hfi1 rx freed\n"); + free_netdev(dd->netdev_rx->rx_napi); kfree(dd->netdev_rx); dd->netdev_rx = NULL; } -- 2.43.0