Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1463903ybi; Fri, 2 Aug 2019 16:31:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPf7U5adyYv5/Z1hEue4zn65iWCQmNAJWOF9JGCVi9dSBOQUdVH4OUKz57d65vfl1Ft1d6 X-Received: by 2002:a17:90a:3544:: with SMTP id q62mr6654902pjb.53.1564788684191; Fri, 02 Aug 2019 16:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564788684; cv=none; d=google.com; s=arc-20160816; b=sAmNWtD0tg+NC6gYxKgO93wjmdfsars0qwKRYpfxM1E5/nP0xK0XGqeXh3bjrlB5CR EjmuFhG99WmvltJKdENkN5uE8v8Iacg6n2HL1j1gpm+kaOusW2q2ah2q8eELXMQkhTZe EgkAwDmAw4wlLE/4wLiVYTMEjPXE7JwIuA0zGsE3gXigGpxKgHlJyOKTduXEb5B6iUhA Xg5cFKd4AN4q/P0MAh8aOCgfQAscCvcpKWFS69uuM3WPjGkiDFq6jTkPxWZUF7jY/Zek 8L3h6WEo27G7j4Byg9eKp11tBqIx67R+oscbCYM4XqBo2kQlgz3G8QVq5Cqo0k9Rc2Da LWIA== 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=B9SvP2xLI0r/IFLODY4SREeRnuK66x7eKEYY7oOsxjs=; b=CFpHyW+QzGav3L+ek3GKQOdgS+vH2ot6hLk7XFwOK/0WhoRWEHE4UPv8yGscAuQGZG dBwhGvb+pyqlJhqsNC6lMOuduH2wbg4mWDUgoIz88OZlLKDDLMZ0eaNhtqdZQyZ7/nXM 6r53B/mKSZqZDNgP5gRzlBJLfHxOQASnu1WxO9Qb5Qtg8UQCKD6XomoSqklIaodJfQov z9XOVC9NamuszUVW5ENH9I/RepB/cJLKXPPjTDbaxhWTPxeYYBL1wFj3dKEn93h5zHnK Uy95bA5quIYhraA0PTd+k3M/kpIZKdVo3x/o1I6bBKsClnaCATspQPO2ZmwcCL8Opx5M JPcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rd7F+uGp; 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 x126si66939000pgx.356.2019.08.02.16.31.09; Fri, 02 Aug 2019 16:31:24 -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=rd7F+uGp; 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 S2392868AbfHBM50 (ORCPT + 99 others); Fri, 2 Aug 2019 08:57:26 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44024 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728921AbfHBM50 (ORCPT ); Fri, 2 Aug 2019 08:57:26 -0400 Received: by mail-pg1-f193.google.com with SMTP id r26so85986pgl.10; Fri, 02 Aug 2019 05:57:25 -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=B9SvP2xLI0r/IFLODY4SREeRnuK66x7eKEYY7oOsxjs=; b=rd7F+uGpcYw7H+IxAjRfwqV33K6RSiW8chDUdhFPRCYZ1HcZETAkYIhhNnPCh0/pCe SMgjY1aYw8nxW6xeZKVp5hlA+R+a0JHCQ1YPqhYYEZ+mlpDOAhOfg0GW4LOT1ziQTlWi FWjYFbIVVp9mbhPSNWSwoT40nS1qAEjbYOKbW41zBvRCL0YfenvKrzmMNfKpQyBmpHO9 iLS10QRzZq2G5Q5T1xxwcijkJXcYJCAu+07oWnhp4gXj/AR1Od2AUV8PIXtj9kRpvxhX RV50VUEykdzxW47VlzY7TGLmNegzlvEHu5q8Uq1/oRKsDKk3/HhKcMy+1BfBJvEooF6b K5jg== 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=B9SvP2xLI0r/IFLODY4SREeRnuK66x7eKEYY7oOsxjs=; b=ObF0ALx14vkgNNDIO+NQQZJfq+WvsofhO5l3A9TjN3p5DFWzaxKz3LdnVoB4hja3l9 JiBJ0n4WAPEN9G5fFR165aDl7m0etD0eCRQsImfHyduTfIP5/05ekYtXz/ppNDTBYNO7 PqFzo+3PhtjEdgj0G3E66707DHNCOGXvdEvkrvvsP5lww5/Ix3ETi8lIVhgispj0WcEI Pe6A/v+DbsT6nPfK60ueUgVX/MxvFlCD7U3qkoTJY2fNEE0ut0t/lAOqiu+4Fmc3G7r6 2KDf5jsErHMf6pNNOPIQhqj1/Mx9tKPTG7UPFIuj+zRAuBWVbqMKkOHDTbzxPtHVwxjx uv8Q== X-Gm-Message-State: APjAAAV0AkeDmjJzI19MU1jUrseq4QugLdTBiW68Xp/T5Cc3yzNiK3sb JyUcAtpz7VFnhz7wIlKydtY= X-Received: by 2002:a17:90a:109:: with SMTP id b9mr4043952pjb.112.1564750645351; Fri, 02 Aug 2019 05:57:25 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id l25sm94389446pff.143.2019.08.02.05.57.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 02 Aug 2019 05:57:24 -0700 (PDT) From: Chuhong Yuan Cc: "David S . Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH] niu: Use refcount_t for refcount Date: Fri, 2 Aug 2019 20:57:20 +0800 Message-Id: <20190802125720.22363-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. Also convert refcount from 0-based to 1-based. Signed-off-by: Chuhong Yuan --- drivers/net/ethernet/sun/niu.c | 6 +++--- drivers/net/ethernet/sun/niu.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c index 0bc5863bffeb..5bf096e51db7 100644 --- a/drivers/net/ethernet/sun/niu.c +++ b/drivers/net/ethernet/sun/niu.c @@ -9464,7 +9464,7 @@ static struct niu_parent *niu_new_parent(struct niu *np, memcpy(&p->id, id, sizeof(*id)); p->plat_type = ptype; INIT_LIST_HEAD(&p->list); - atomic_set(&p->refcnt, 0); + refcount_set(&p->refcnt, 1); list_add(&p->list, &niu_parent_list); spin_lock_init(&p->lock); @@ -9524,7 +9524,7 @@ static struct niu_parent *niu_get_parent(struct niu *np, port_name); if (!err) { p->ports[port] = np; - atomic_inc(&p->refcnt); + refcount_inc(&p->refcnt); } } mutex_unlock(&niu_parent_lock); @@ -9552,7 +9552,7 @@ static void niu_put_parent(struct niu *np) p->ports[port] = NULL; np->parent = NULL; - if (atomic_dec_and_test(&p->refcnt)) { + if (refcount_dec_and_test(&p->refcnt)) { list_del(&p->list); platform_device_unregister(p->plat_dev); } diff --git a/drivers/net/ethernet/sun/niu.h b/drivers/net/ethernet/sun/niu.h index 04c215f91fc0..755e6dd4c903 100644 --- a/drivers/net/ethernet/sun/niu.h +++ b/drivers/net/ethernet/sun/niu.h @@ -3071,7 +3071,7 @@ struct niu_parent { struct niu *ports[NIU_MAX_PORTS]; - atomic_t refcnt; + refcount_t refcnt; struct list_head list; spinlock_t lock; -- 2.20.1