Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp743759ybh; Sat, 3 Aug 2019 08:54:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaCnrsDdafTN7Nh/nwCLopzQFX66iU5wN/SNsePDqYA1DPQ0jQUDlK15/29P11mjp6oINk X-Received: by 2002:a17:902:82c4:: with SMTP id u4mr136591301plz.196.1564847675488; Sat, 03 Aug 2019 08:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564847675; cv=none; d=google.com; s=arc-20160816; b=h0Gq1eB1AETTHvI28MOdoTTlE9eE2idNAmA3swFvlH6MNAsFoBrjuaAYn6NrzX50n8 ohbQOqD810B8SNB8Q8QBJ4Gwc4+ZsuVCk0DbK8wt3uupp4vIDyI6svHD+bM2RQBRjjhO oLWeQLvLFFcWWsXGFJteBFzeCohC4rd5bmWj7upo2FdHf4tTdOPj5HDzDf/CkPUNeXp+ hfXhmFx3ULTS/PywXn4f3UgtYSXbTPiXfw0O2kO+QYWq+15gwQZUuP2WDnYb/Mp7mMFp CbAc1dHcmMBbVhmDPuCMZ4c7ySjVWf4rEIKvci5dLxWU/Wh/C2dxCxhussRbWBXmK2DD yHgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=YgwNXbdRzIMClAStYn5LCztSjKPnlA/LIgZ8UT/xatA=; b=omCAeRCqnPvQotRqCaR5PfPfqAJaSdSUJuad3CdwtcBwu1GI78rZZkykbYbCEmkLV8 wF7QY0qTeSLWLrzBJ4oatj+sbk71jGaHEWOzH4DIqdrjCBi46Lw5SMSAC83tWZsZQ2SG j12QtQsYdxhJhQ9k+EL5wyNpo3i4CwbOLFHlbHQX41YKc3JlBXLv6Owb1KLrujW3Fbrw lubaC6LWwAn79skfLSqKhrub/ZVtFt4LzuUm3pU3orcj4A93CVetigDXS8u1rZDIl9zT YAmfPXeO7jhYpQCpoA0mZ8hGgk1tSIGBS6N55JLH83I0yzDq/WMY7Q6pvRHk/pzzaBvY 5YIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UZDxJOLn; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 39si36082695pla.73.2019.08.03.08.54.20; Sat, 03 Aug 2019 08:54:35 -0700 (PDT) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UZDxJOLn; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391286AbfHBQsf (ORCPT + 99 others); Fri, 2 Aug 2019 12:48:35 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37135 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388211AbfHBQse (ORCPT ); Fri, 2 Aug 2019 12:48:34 -0400 Received: by mail-pg1-f194.google.com with SMTP id d1so3528302pgp.4; Fri, 02 Aug 2019 09:48:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YgwNXbdRzIMClAStYn5LCztSjKPnlA/LIgZ8UT/xatA=; b=UZDxJOLnyvIswpZAxRFxNHwJm7Sbkf3AJsD7L880wY/ytbPBIqrn41SiyqfmmNkP0x 51xVnMUUExEV7nKSioYeuLKhH3igFZ2dDoSruiyutXOd4HWje7n8SCbTVZHmVZTbCPLQ WoMSTfIUDMoTmTfXnHs8ntlzFphDeLT8zdrKCJzYpaKMTUfyuWdjxwF+9IZX4sKxz+Y0 iItIvWi9aezEG+60j+jsr7JtlUW6o9p2vadfuSc4hDe877ZUfjaZvSRriMPBwH3DrdzP zoKkMLM8ii9asLUbdgNaSkRmD03zWs3HN8i4Kkm/xiYm5eI9XyhPlweKi4wNKdgMNTGR jYWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YgwNXbdRzIMClAStYn5LCztSjKPnlA/LIgZ8UT/xatA=; b=Nw01D/lG1oKYfkDyfm2L9ItFT4Flu1CMFtvJhVxHewydgCd5GklGV7r3+TWxup4Tuo KTZ3w7YPL9uvXSlrHD/5YGahswDU9TXPP7nUvSJ+9RFkZNBLoCKk/hq7uPiAmIBelVsm 8B131sFmRYfLJpjH87vmjQFAJ44dlCiFdxjscmDe02A5AhMwkrqmsuGKlYWMpnbf9Msz T+lfWAW9TaMj9HH1qRj6daMiyOG3BwVC8vvAzZv+N5DYcLDSeif2u6G5OE5z305Rfndk J/6eXOs9Q6Y1gfhCivyC7cm2eGET9fmdAGq3S2SW5pWtBnCanZag2E6+umE+XpJ4s0aC VNXQ== X-Gm-Message-State: APjAAAUyv3NL73nVSuhqWlvmRWpccJibz05w0VYYMmThmhG6XWdSrUL0 OPsWWIKYIgOxqSaBH+j3Stk= X-Received: by 2002:a17:90a:898e:: with SMTP id v14mr5176595pjn.119.1564764513767; Fri, 02 Aug 2019 09:48:33 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id m31sm14470902pjb.6.2019.08.02.09.48.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 02 Aug 2019 09:48:33 -0700 (PDT) From: Chuhong Yuan Cc: Saeed Mahameed , Leon Romanovsky , "David S . Miller" , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v2] net/mlx5e: Use refcount_t for refcount Date: Sat, 3 Aug 2019 00:48:28 +0800 Message-Id: <20190802164828.20243-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org refcount_t is better for reference counters since its implementation can prevent overflows. So convert atomic_t ref counters to refcount_t. Signed-off-by: Chuhong Yuan --- Changes in v2: - Add #include. drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c index b9d4f4e19ff9..148b55c3db7a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include "mlx5_core.h" @@ -48,7 +49,7 @@ struct mlx5_vxlan { struct mlx5_vxlan_port { struct hlist_node hlist; - atomic_t refcount; + refcount_t refcount; u16 udp_port; }; @@ -113,7 +114,7 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) vxlanp = mlx5_vxlan_lookup_port(vxlan, port); if (vxlanp) { - atomic_inc(&vxlanp->refcount); + refcount_inc(&vxlanp->refcount); return 0; } @@ -137,7 +138,7 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) } vxlanp->udp_port = port; - atomic_set(&vxlanp->refcount, 1); + refcount_set(&vxlanp->refcount, 1); spin_lock_bh(&vxlan->lock); hash_add(vxlan->htable, &vxlanp->hlist, port); @@ -170,7 +171,7 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) goto out_unlock; } - if (atomic_dec_and_test(&vxlanp->refcount)) { + if (refcount_dec_and_test(&vxlanp->refcount)) { hash_del(&vxlanp->hlist); remove = true; } -- 2.20.1