mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>, Christoph Hellwig <hch@lst.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Marco Elver <elver@google.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Kees Cook <kees@kernel.org>, Jann Horn <jannh@google.com>,
	linux-kernel@vger.kernel.org,
	Bart Van Assche <bvanassche@acm.org>,
	Dragos Tatulea <dtatulea@nvidia.com>,
	Cosmin Ratiu <cratiu@nvidia.com>,
	Lior Nahmanson <liorna@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH RFC 16/33] net/mlx5e: Make the code easier to analyze
Date: Thu,  6 Feb 2025 09:50:57 -0800	[thread overview]
Message-ID: <20250206175114.1974171-17-bvanassche@acm.org> (raw)
In-Reply-To: <20250206175114.1974171-1-bvanassche@acm.org>

Make it possible for clang to perform its compile-time thread-safety
analysis by making the arguments of mutex_lock() and mutex_unlock() derived
from function arguments instead of local variables. Additionally, move
initializers of variables that are not changed into the declaration block.

Cc: Dragos Tatulea <dtatulea@nvidia.com>
Cc: Cosmin Ratiu <cratiu@nvidia.com>
Cc: Lior Nahmanson <liorna@nvidia.com>
Cc: Tariq Toukan <tariqt@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 .../mellanox/mlx5/core/en_accel/macsec.c      | 62 +++++++------------
 1 file changed, 24 insertions(+), 38 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
index 6ab02f3fc291..97d8fcde3648 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
@@ -510,12 +510,11 @@ static int mlx5e_macsec_add_txsa(struct macsec_context *ctx)
 	struct mlx5_core_dev *mdev = priv->mdev;
 	u8 assoc_num = ctx->sa.assoc_num;
 	struct mlx5e_macsec_sa *tx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
+	mutex_lock(&macsec->lock);
 
-	macsec = priv->macsec;
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -581,13 +580,12 @@ static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
 	struct mlx5e_macsec_device *macsec_device;
 	u8 assoc_num = ctx->sa.assoc_num;
 	struct mlx5e_macsec_sa *tx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	struct net_device *netdev;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
+	mutex_lock(&macsec->lock);
 
-	macsec = priv->macsec;
 	netdev = ctx->netdev;
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
@@ -641,11 +639,10 @@ static int mlx5e_macsec_del_txsa(struct macsec_context *ctx)
 	struct mlx5e_macsec_device *macsec_device;
 	u8 assoc_num = ctx->sa.assoc_num;
 	struct mlx5e_macsec_sa *tx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -679,11 +676,10 @@ static int mlx5e_macsec_add_rxsc(struct macsec_context *ctx)
 	struct mlx5e_macsec_device *macsec_device;
 	struct mlx5e_macsec_rx_sc *rx_sc;
 	struct list_head *rx_sc_list;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -759,14 +755,12 @@ static int mlx5e_macsec_upd_rxsc(struct macsec_context *ctx)
 	struct mlx5e_macsec_device *macsec_device;
 	struct mlx5e_macsec_rx_sc *rx_sc;
 	struct mlx5e_macsec_sa *rx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	struct list_head *list;
 	int i;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
-
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -838,13 +832,11 @@ static int mlx5e_macsec_del_rxsc(struct macsec_context *ctx)
 	struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
 	struct mlx5e_macsec_device *macsec_device;
 	struct mlx5e_macsec_rx_sc *rx_sc;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	struct list_head *list;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
-
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -879,13 +871,11 @@ static int mlx5e_macsec_add_rxsa(struct macsec_context *ctx)
 	struct mlx5e_macsec_rx_sc *rx_sc;
 	sci_t sci = ctx_rx_sa->sc->sci;
 	struct mlx5e_macsec_sa *rx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	struct list_head *list;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
-
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -963,13 +953,11 @@ static int mlx5e_macsec_upd_rxsa(struct macsec_context *ctx)
 	struct mlx5e_macsec_rx_sc *rx_sc;
 	sci_t sci = ctx_rx_sa->sc->sci;
 	struct mlx5e_macsec_sa *rx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	struct list_head *list;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
-
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -1020,13 +1008,11 @@ static int mlx5e_macsec_del_rxsa(struct macsec_context *ctx)
 	struct mlx5e_macsec_rx_sc *rx_sc;
 	u8 assoc_num = ctx->sa.assoc_num;
 	struct mlx5e_macsec_sa *rx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	struct list_head *list;
 	int err = 0;
 
-	mutex_lock(&priv->macsec->lock);
-
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -1078,8 +1064,9 @@ static int mlx5e_macsec_add_secy(struct macsec_context *ctx)
 	if (!mlx5e_macsec_secy_features_validate(ctx))
 		return -EINVAL;
 
-	mutex_lock(&priv->macsec->lock);
 	macsec = priv->macsec;
+
+	mutex_lock(&macsec->lock);
 	if (mlx5e_macsec_get_macsec_device_context(macsec, ctx)) {
 		netdev_err(netdev, "MACsec offload: MACsec net_device already exist\n");
 		goto out;
@@ -1180,9 +1167,9 @@ static int mlx5e_macsec_upd_secy(struct macsec_context *ctx)
 	if (!mlx5e_macsec_secy_features_validate(ctx))
 		return -EINVAL;
 
-	mutex_lock(&priv->macsec->lock);
-
 	macsec = priv->macsec;
+
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");
@@ -1229,13 +1216,12 @@ static int mlx5e_macsec_del_secy(struct macsec_context *ctx)
 	struct mlx5e_macsec_device *macsec_device;
 	struct mlx5e_macsec_rx_sc *rx_sc, *tmp;
 	struct mlx5e_macsec_sa *tx_sa;
-	struct mlx5e_macsec *macsec;
+	struct mlx5e_macsec *macsec = priv->macsec;
 	struct list_head *list;
 	int err = 0;
 	int i;
 
-	mutex_lock(&priv->macsec->lock);
-	macsec = priv->macsec;
+	mutex_lock(&macsec->lock);
 	macsec_device = mlx5e_macsec_get_macsec_device_context(macsec, ctx);
 	if (!macsec_device) {
 		netdev_err(ctx->netdev, "MACsec offload: Failed to find device context\n");

  parent reply	other threads:[~2025-02-06 17:52 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 17:50 [PATCH RFC 00/33] Compile-time thread-safety checking Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 01/33] scsi, usb: Rename the RESERVE and RELEASE constants Bart Van Assche
2025-02-07  3:44   ` Christoph Hellwig
2025-02-06 17:50 ` [PATCH RFC 02/33] s390: Comment out the RELEASE constant Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 03/33] locking: Introduce <linux/thread_safety.h> Bart Van Assche
2025-02-07  3:53   ` Christoph Hellwig
2025-02-07  8:29     ` Marco Elver
2025-02-07 22:34     ` Bart Van Assche
2025-02-07 23:19       ` Marco Elver
2025-02-07 23:50         ` Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 04/33] include/linux/cleanup.h: Support thread-safety analysis Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 05/33] locking/mutex: Change the atomic_dec_and_mutex_lock() return type Bart Van Assche
2025-02-07  3:47   ` Christoph Hellwig
2025-02-06 17:50 ` [PATCH RFC 06/33] locking/mutex: Annotate struct mutex and mutex functions Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 07/33] driver core: Annotate locking functions in <linux/device.h> Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 08/33] kref: Add thread-safety annotations in <linux/kref.h> Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 09/33] refcount: Add thread-safety annotations in <linux/refcount.h> Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 10/33] treewide: Modify mutex_lock_interruptible() return value checks Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 11/33] PNP: isapnp: Check the isapnp_cfg_begin() return value Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 12/33] scsi: mpi3mr: Fix locking in an error path Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 13/33] scsi: mpt3sas: Fix a locking bug " Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 14/33] ice: Split ice_dcb_rebuild() Bart Van Assche
2025-02-06 22:01   ` Przemek Kitszel
2025-02-06 17:50 ` [PATCH RFC 15/33] ice: Fix a locking bug in an error path Bart Van Assche
2025-02-06 21:35   ` Tony Nguyen
2025-02-06 21:44     ` Bart Van Assche
2025-02-06 21:48       ` Tony Nguyen
2025-02-06 17:50 ` Bart Van Assche [this message]
2025-02-06 17:50 ` [PATCH RFC 17/33] Input: synaptics-rmi4 - fix " Bart Van Assche
2025-02-06 17:50 ` [PATCH RFC 18/33] misc: nsm: Fix " Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 19/33] drm/amdgpu: Unlock a mutex before destroying it Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 20/33] drm/amdgpu: Fix a locking bug in an error path Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 21/33] drm/amdgpu: Fix locking bugs in error paths Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 22/33] drm: bridge: cdns-mhdp8546: Fix a locking bug in an error path Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 23/33] " Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 24/33] drm: zynqmp_dp: Fix a deadlock in zynqmp_dp_ignore_hpd_set() Bart Van Assche
2025-02-06 19:22   ` Sean Anderson
2025-02-06 20:24     ` Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 25/33] wifi: ath12k: Fix locking in error paths Bart Van Assche
2025-02-06 18:25   ` Jeff Johnson
2025-02-06 22:13     ` Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 26/33] mctp i3c: " Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 27/33] iavf: Fix a locking bug in an error path Bart Van Assche
2025-02-12  2:03   ` Jakub Kicinski
2025-02-06 17:51 ` [PATCH RFC 28/33] wifi: mt76: mt7925: " Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 29/33] hwmon: (it87) Check the it87_lock() return value Bart Van Assche
2025-02-06 22:51   ` Guenter Roeck
2025-02-06 23:34     ` Bart Van Assche
2025-02-06 23:41       ` Guenter Roeck
2025-02-09  5:04         ` Frank Crawford
2025-02-07  3:45     ` Christoph Hellwig
2025-02-06 17:51 ` [PATCH RFC 30/33] drivers/net/ethernet/marvell/octeontx2/nic: Fix locking in an error path Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 31/33] md/raid*: Fix raid*_set_queue_limits() Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 32/33] treewide: Annotate all struct mutex users Bart Van Assche
2025-02-06 17:51 ` [PATCH RFC 33/33] kbuild: clang: Unconditionally enable thread-safety checking Bart Van Assche
2025-02-06 18:20 ` [PATCH RFC 00/33] Compile-time " Marco Elver
2025-02-06 18:34   ` Bart Van Assche
2025-02-07  8:42     ` Peter Zijlstra
2025-02-07  9:05       ` Marco Elver
2025-02-07  9:08         ` Peter Zijlstra
2025-02-07  9:41           ` Marco Elver
2025-02-07 17:46           ` Bart Van Assche
2025-02-07 18:24             ` Marco Elver
2025-02-07 18:35               ` Bart Van Assche
2025-02-07 18:54                 ` Marco Elver
2025-02-07  3:44   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250206175114.1974171-17-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=cratiu@nvidia.com \
    --cc=dtatulea@nvidia.com \
    --cc=elver@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=jannh@google.com \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liorna@nvidia.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=tariqt@nvidia.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®