Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6147041ybi; Wed, 31 Jul 2019 09:07:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOjOdkN1m6OR7aQYpNq2SKXG/DiIEcPOVY/vMmDAKqajV3GvW3QfBsSr+e393TSgoV1t3G X-Received: by 2002:a62:ae01:: with SMTP id q1mr47062344pff.219.1564589226177; Wed, 31 Jul 2019 09:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564589226; cv=none; d=google.com; s=arc-20160816; b=N2EpadnPS2bUCkJUZs6uzjUm1/kgNVkAVH5JbKAkIPyOJWv3Zj4dF5JaHSydHlsuo0 hlj3hYWYMBzbi1oXfftHCgfvWqhb/aHEpyShArfYAJRNqdP5GS8HyDt5ADlsMMTYTWlg yM72yRRoAJAdPQjUu8Ur1SuRXuDpVM8ISke7hpxQb67Ejsfbusez6Wn5NPibS3Mu3otJ qVKqdyuj8nnkImo6DfxpdphRHmxLbyjM/wQimI0wDKz/i5SApHDn4cj4J8vXhQSpcWVT FB4DRe3t3oYKjcjOUhXG4b4kRfJ82ibq3/JYbbC5u4nwy3WmLouQDvf2S+kcZSNzz3gL 7/Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fRRqwkpcI53teRjcOkCo/u4yNvkJ3n0LBJJNlhIbQKs=; b=SAO8PT/eNzaPGW/Ri+x/l634NLPn2QWqQ0tRri/Z7yzb322F2MpSa3nJ+w79j0mP/x vFb0mkwSN8Mq2KfGxMvNqzLaDWmBRluJ8CH3Xaq15o7ukiOtVq1GIpFxbpvbXuj4lmmO FGTT0g0M+6S6cdW3h9oWl4di7SKWG2MT++7NJF6YYTdnGqX52i34XKKGd0F/N5Xrf9Cm W5Lr8Z+ENBKX4CjB8LE/bWrZ1EMZAeW/VNWlJQD5J/9wxW8pcee2vLKIgBPQsjgZzLlr aR0IlL4sNRvRNrgCrOEqQ3doF5Zhig8NaTZVYu3dFkdgWDFeXaCDLvhdzc0uMS/M+Iw4 W/3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="P3jTJ/Wx"; 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=pass (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 a21si33668294pfl.167.2019.07.31.09.06.50; Wed, 31 Jul 2019 09:07:06 -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=pass header.i=@gmail.com header.s=20161025 header.b="P3jTJ/Wx"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729834AbfGaQGB (ORCPT + 99 others); Wed, 31 Jul 2019 12:06:01 -0400 Received: from mail-yb1-f194.google.com ([209.85.219.194]:36741 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727230AbfGaQGB (ORCPT ); Wed, 31 Jul 2019 12:06:01 -0400 Received: by mail-yb1-f194.google.com with SMTP id d9so18198289ybf.3 for ; Wed, 31 Jul 2019 09:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fRRqwkpcI53teRjcOkCo/u4yNvkJ3n0LBJJNlhIbQKs=; b=P3jTJ/Wx48996sLijiWGaUjfbi/B/kCcMzSSuKiU019fryrueyi8hgODOU+xLAoy0D YQuL9F5OvtJm02BhWy+w5navYIeYstp6V+l18UOO4aB0iuPJVD8hoc1sdrUaaXNrVgzc l9FV0Crx/OlP6BgCeJ5WZE++YYZ+QxuE/3OrVPToJn+iWQ5xMOoBtgE3wSwPjhBVDAgI NWPOP6y79ZJQMEdsY8hRAhzfQre2pvIbGGOi5olgXBuZT/X/Uou24Ex7ed8K9L/93tyM FA8qMaXy7Qlzn4jwO+mKuZwufKiCeFOzc0wbauHUDOyuMz1Wsf4k25gf/Yl2DsG9jutU h/+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fRRqwkpcI53teRjcOkCo/u4yNvkJ3n0LBJJNlhIbQKs=; b=AMJWs6zTQZz0qN2RTuavYmHQQ5PaIMSSt3MZpIwraxQLescNHQZL1ctw/VLCq7dhLe dGONGzwcTpiZBSRk+AvaJr+M4d1FhejJbRnzLoNmHl7DkkPJFA/cp0Vk9mpDKAdfcUck WfrEfFVgFRihK83LjeuYSHqPWbLVYmqFqhWfS95YUUsVTcX8kqnKc6xKO/OrocCorY2S HJ4En6yQiNirtUd2W9TnoJol8X8Vqn79LC/zraQBxVXSpnZVkvK9y4dv52FFg66qGZtS 77v5pjigsbitVAW+RruGDWd5IumEYWtSvUU34b5gM2DUReLPgXUv3kf9ksrQcidBbRLI HYKA== X-Gm-Message-State: APjAAAUvLaADJhezTYZgk2BFJla1CF7/gHKOgOrnQVdqMApXyx1MTx4N uLkCrozotW2fX0SzYba0iIKdz6GQ X-Received: by 2002:a25:9c83:: with SMTP id y3mr31006763ybo.455.1564589159661; Wed, 31 Jul 2019 09:05:59 -0700 (PDT) Received: from mail-yw1-f47.google.com (mail-yw1-f47.google.com. [209.85.161.47]) by smtp.gmail.com with ESMTPSA id t201sm16172758ywc.87.2019.07.31.09.05.58 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 09:05:58 -0700 (PDT) Received: by mail-yw1-f47.google.com with SMTP id z197so25141534ywd.13 for ; Wed, 31 Jul 2019 09:05:58 -0700 (PDT) X-Received: by 2002:a0d:cc48:: with SMTP id o69mr70364492ywd.389.1564589158227; Wed, 31 Jul 2019 09:05:58 -0700 (PDT) MIME-Version: 1.0 References: <20190731122203.948-1-hslester96@gmail.com> In-Reply-To: <20190731122203.948-1-hslester96@gmail.com> From: Willem de Bruijn Date: Wed, 31 Jul 2019 12:05:22 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] bnxt_en: Use refcount_t for refcount To: Chuhong Yuan Cc: Michael Chan , "David S . Miller" , Network Development , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 31, 2019 at 8:22 AM Chuhong Yuan wrote: > > 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 > --- > drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 8 ++++---- > drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h | 2 +- > 2 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c > index fc77caf0a076..eb7ed34639e2 100644 > --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c > +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c > @@ -49,7 +49,7 @@ static int bnxt_register_dev(struct bnxt_en_dev *edev, int ulp_id, > return -ENOMEM; > } > > - atomic_set(&ulp->ref_count, 0); > + refcount_set(&ulp->ref_count, 0); One feature of refcount_t is that it warns on refcount_inc from 0 to detect possible use-after_free. It appears that that can trigger here? > ulp->handle = handle; > rcu_assign_pointer(ulp->ulp_ops, ulp_ops); > > @@ -246,12 +246,12 @@ static int bnxt_send_msg(struct bnxt_en_dev *edev, int ulp_id, > > static void bnxt_ulp_get(struct bnxt_ulp *ulp) > { > - atomic_inc(&ulp->ref_count); > + refcount_inc(&ulp->ref_count); > }