Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3219632imu; Sat, 24 Nov 2018 00:23:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/VNzPaUhpLynta15oy+Xc9fQMhPWx8+Sltr/pZ3LU+XMrYsJqBvgRRt/Q4mcr2dUxs20FfO X-Received: by 2002:a17:902:7686:: with SMTP id m6mr19497878pll.179.1543047828010; Sat, 24 Nov 2018 00:23:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543047827; cv=none; d=google.com; s=arc-20160816; b=0C40V05eNTcn2Tu3g2i10VIuUdcK+bD9wNv/QfdGopHMv70W/jR8VSME9EFIJjG4QK hiw2hWdi4O/ZQRBXnFuHQbWuJ+tUpJc8Y9oC29QGqsKEpKVlNR7ve36SNPR2SBHJSckF PcL11PvhQTHSCUlwJPL7vVbhiFf6qxI/ePD0Tt325F+vWaM7m4P4W4mk8eVCYy974O0Q ZBxxU7Uj/zMHAQ5CnkUbGPZqgevCa9xrjGPc2JlBV2xMRjB9H4BF5v4/atkKhq726rIC 9pqBYitSeLVRblLEcyYZf8AMvUXkIzR2ERDGyYzCUyoaX8CpDv0GGk48w20r2sRmdD1U hs/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=YUd68lT+Nbs1CuYWfgadotcTcrWCer+xWXfaNUArWhM=; b=ujOjswzUFSUAiT6bJd27v647aNoLzpAELi5nJ2W3VRU1692CTCnkSosBZ+SkwIc0I1 hkLac1F8N57+c2n0k0rCDjNvXMDJyBiNshfVq2zn0+xK0vlAXuZYCfz62ZIwxPrkVX4m jhK5ex/qqmIXV5ITia1wEWe3yHs4iP1VHTQBpNS80C+9Ldd7HoL93su/XqF0OwgrJm1b HQpi/NF3wz8cBDmSQnHFvP6j7c3HCIF1g/32rzkTG6XXoklhK0N5FjQmjWBs2iKkqDgf d5xJcOfObUfsmNTZ71HPO/BBQJxr9PMkchsaSwM7D9gtZcObvlksoC4I4Bu5JDh0jKXw pitw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=EebVeko2; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si40476754pls.348.2018.11.24.00.23.33; Sat, 24 Nov 2018 00:23:47 -0800 (PST) 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=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=EebVeko2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503146AbeKWUsr (ORCPT + 99 others); Fri, 23 Nov 2018 15:48:47 -0500 Received: from mail-vk1-f195.google.com ([209.85.221.195]:43575 "EHLO mail-vk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393839AbeKWUsr (ORCPT ); Fri, 23 Nov 2018 15:48:47 -0500 Received: by mail-vk1-f195.google.com with SMTP id o130so2545288vke.10 for ; Fri, 23 Nov 2018 02:05:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=owltronix-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=YUd68lT+Nbs1CuYWfgadotcTcrWCer+xWXfaNUArWhM=; b=EebVeko2mmI5SWtPIR/svf3tE1WPbBR+a6wqVVBgi2l2k4J6oIBkZnhiDXBs7L5ToE c9mz7ptIEZ+nF8T3Y0lVBLAMT1Sz41raMant5AZveh9rKMsd6W6aUmq2umPcoHLhswbk aV0LzE/8jM4p3hosvcL5qg10piQW5PT/KP2/0Fr/P3XaYgDQwqljvEgH+3WuYx/PCpGJ gb/Hy1sB3jyE3r+xcsJMihNxA4Kwmvu9Ea+aygpE1ydzqV6u311LLnWsgPJ5PnbFk0Xa EKHY1vSP59SOrHfBMsXaZoqlsgWFzA7ud92yzcisAxgHzc3pLOSSv/xumsk1+JBXulyZ GboQ== 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:content-transfer-encoding; bh=YUd68lT+Nbs1CuYWfgadotcTcrWCer+xWXfaNUArWhM=; b=gpmgX+O+BCY2kKsipSDz8IRBJRS6npjE6zWEznmJaJrEFrUB/aq7orJ0OpffRaP/hr lO0Pb45FI+06jRyVNcOAZXYk/5Su7u0xgfhnYea2Pdj8XjB9QRotReP0ePf3tJaubHBX W/raSe1w2IG9JgJVWdynk7AzxSqZHOZtvOe6eNG8xu9jflaStiPAvlR85XEnk1xm/HhC S27rwkVWLPb4sNrzEvVW6iWnK7qtRll35+SXa1mNYOOk32C4oU+cjAt8E2LnozbndT4E XLq6Vr8nr7tFsI4HK2INpdzp9+ViKw3HmIql2WfB89DBkEDdCX9MGgW2lleWd07d5pXu fRBQ== X-Gm-Message-State: AA+aEWZ3TAyGOh/5HWeKLVIgGg6M31PrhalhvqEdalWmHqhKtVSdGCxv CUGy1Wg/ksHfFfPCAZRdTgLl5GfZYlaPVdppAjuk/majORw= X-Received: by 2002:a1f:8b48:: with SMTP id n69mr5988322vkd.12.1542967509671; Fri, 23 Nov 2018 02:05:09 -0800 (PST) MIME-Version: 1.0 References: <1542894410-14047-1-git-send-email-javier@cnexlabs.com> <1542894410-14047-2-git-send-email-javier@cnexlabs.com> In-Reply-To: <1542894410-14047-2-git-send-email-javier@cnexlabs.com> From: Hans Holmberg Date: Fri, 23 Nov 2018 11:04:58 +0100 Message-ID: Subject: Re: [PATCH] lightnvm: pblk: avoid ref warning on cache creation To: =?UTF-8?Q?Javier_Gonz=C3=A1lez?= Cc: Matias Bjorling , Hans Holmberg , linux-block@vger.kernel.org, Linux Kernel Mailing List , Javier Gonzalez Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Great catch Javier! Nice refactoring work too. Reviewed-by: Hans Holmberg On Thu, Nov 22, 2018 at 2:47 PM Javier Gonz=C3=A1lez w= rote: > > The current kref implementation around pblk global caches triggers a > false positive on refcount_inc_checked() (when called) as the kref is > initialized to 0. Instead of usint kref_inc() on a 0 reference, which is > in principle correct, use kref_init() to avoid the check. This is also > more explicit about what actually happens on cache creation. > > In the process, do a small refactoring to use kref helpers. > > Signed-off-by: Javier Gonz=C3=A1lez > --- > drivers/lightnvm/pblk-init.c | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) > > diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c > index 13822594647c..e225bd60cbb4 100644 > --- a/drivers/lightnvm/pblk-init.c > +++ b/drivers/lightnvm/pblk-init.c > @@ -350,23 +350,19 @@ static int pblk_create_global_caches(void) > > static int pblk_get_global_caches(void) > { > - int ret; > + int ret =3D 0; > > mutex_lock(&pblk_caches.mutex); > > - if (kref_read(&pblk_caches.kref) > 0) { > - kref_get(&pblk_caches.kref); > - mutex_unlock(&pblk_caches.mutex); > - return 0; > - } > + if (kref_get_unless_zero(&pblk_caches.kref)) > + goto out; > > ret =3D pblk_create_global_caches(); > - > if (!ret) > - kref_get(&pblk_caches.kref); > + kref_init(&pblk_caches.kref); > > +out: > mutex_unlock(&pblk_caches.mutex); > - > return ret; > } > > -- > 2.7.4 >