Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3478433imu; Fri, 30 Nov 2018 00:38:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/WXJwUM7hCLANI3D212MLwlt4++eTqYtJmzZK2RhPlFtzJh1IGfso8uXIk04daiVwG3QXEZ X-Received: by 2002:a17:902:aa8c:: with SMTP id d12mr4879352plr.25.1543567086672; Fri, 30 Nov 2018 00:38:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543567086; cv=none; d=google.com; s=arc-20160816; b=J0Yap86uk3h329sLiRnbDwZPp2boqrzJlzNDCEOadhQsQfU5oH3WuI3LP8JMo+DQcl 6FMCGhyBZ3ZxHpKt2n07K2IyNBTrfJN0bJovhtkMxHG9Uh1cpIyTD2bb+ayIg/4Muddu UitvedvwV0E0Reg1R+SaWUtLXp83b9ttPoJzLOeUJVVuh0kxk7vH+RgVD2tnNAY86Qa/ rCav1zcH2yQDdr4d/tftiBOpFFF4ZK7ySupp8fAP3h/EYpwxfDH+k7i+N0bpjk9zLWfB ffkf0czd7sbvRwWRtvvpg31/dN84aUHzgpqDnolInpSpqYlgGENbe9VBFtNDgOnT4zHG xJrA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=ioXF4bCL8BuwqWo5CCjgjpGdZH7diIK4hexxj1Nvf8o=; b=QpJJR7xvoA3TONPeTjAW1ZvM6BnBOi0MItf7QDspIUsqc6LOIQegdnhV+ek/lttaDx 7uq9OcwIFVrmpQJ/8U5MlabKsJ+JfSpNb8uFNSLHQzlgmF4hdPObam5H0igMhVBnVY/M o1GrAGTYkYUIfjyGwpsw7QISYki45Sr7zbVPDK3wLUznhpltAEnesgwQIUh3zR1wvHKB rS+pSoEr6AaUI++yL3XkcQwsxYG1WKhkf7bUrD4HbRVrtEbOcq3SCOdA8al56h5qWVZI CqWF+b3BlpKxfxPoNeBuqjtw3rzlx7eLH3Rc8iJYalzucuiTuo7Qs793w0KRydL/Wale FH8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=RsAPHWwK; 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 k6si4513798pgr.500.2018.11.30.00.37.51; Fri, 30 Nov 2018 00:38:06 -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=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=RsAPHWwK; 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 S1727190AbeK3To6 (ORCPT + 99 others); Fri, 30 Nov 2018 14:44:58 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:44775 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727148AbeK3To6 (ORCPT ); Fri, 30 Nov 2018 14:44:58 -0500 Received: by mail-lj1-f193.google.com with SMTP id k19-v6so4219790lji.11 for ; Fri, 30 Nov 2018 00:36:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=ioXF4bCL8BuwqWo5CCjgjpGdZH7diIK4hexxj1Nvf8o=; b=RsAPHWwKdpngwQoodtjN35xFxp6L4Ne2axZleCQscGRB1vuT9Aw65WogQB0cJZ/bn5 KrZ4Gu5Yw0xz3E0mPzCyv4jwMo70yGzqVA3k9Xr4pSwWC0ueteybKeZ88m1wuke+oD/3 12hgrzzCwGQV1dmTLxjEvm+oM22RJ9pWrhNoe+vKdPYCiH6qaVfXNQr+pimM4qy+HzqW wtzRDeg9ODyDCntGvTtPjWWP6LBJa0MtREyek8ULqdIgtlpZLnHw8Ly+1DGisEiAjEpX H5YdyMr1mbf9zP0BoAbUBjA/2lr5RHH54B+140YNVMK610nM7OJQdEqdXL6QQaATCxiZ z7LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ioXF4bCL8BuwqWo5CCjgjpGdZH7diIK4hexxj1Nvf8o=; b=mOssDx7/7sgd5nFQtxFPDqSenNXS6pChGhXiiTSeGJjk+AJa8E7knVDkURreAQAKfN Qiyo+uHdM0ajORkrSAZd0Vnkj6XkPJMjrfu7YlvZXs0IgBIEIoLdr14FxyEe+1eadWAv 1DtanxLKuvW7HUf+SUEsC9XsbWKPQXt7/NSkMCRhuhlzXrq+t8KCFZQFoIvNDbWsql9h 3YA1GWQmbf/CgPSk07bFUvR7TAO9v/aG9+5yRDp0bNOMis8tDHMeidSDF+0aPbfKKL1S fQWukpTSBChCK2Uoti6HJor7H2ob0O7UKmUfb1bJV0atog3mDUgt/9Fu48yQljIUoPTy iD4A== X-Gm-Message-State: AA+aEWYsmbE6NSB9wcyjfKRlHUZFu90uRwuCCYYLU7IT3p4Xf5w8pn9H DlGVrlc3olVe9h79l5DmfZJWpg== X-Received: by 2002:a2e:994:: with SMTP id 142-v6mr2903040ljj.120.1543566983755; Fri, 30 Nov 2018 00:36:23 -0800 (PST) Received: from [192.168.0.36] (95-166-82-66-cable.dk.customer.tdc.net. [95.166.82.66]) by smtp.googlemail.com with ESMTPSA id j138sm692946lfg.64.2018.11.30.00.36.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:36:23 -0800 (PST) Subject: Re: [PATCH] lightnvm: pblk: avoid ref warning on cache creation To: Hans Holmberg , =?UTF-8?Q?Javier_Gonz=c3=a1lez?= Cc: Hans Holmberg , linux-block@vger.kernel.org, Linux Kernel Mailing List , Javier Gonzalez References: <1542894410-14047-1-git-send-email-javier@cnexlabs.com> <1542894410-14047-2-git-send-email-javier@cnexlabs.com> From: =?UTF-8?Q?Matias_Bj=c3=b8rling?= Message-ID: Date: Fri, 30 Nov 2018 09:36:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/23/2018 11:04 AM, Hans Holmberg wrote: > Great catch Javier! Nice refactoring work too. > > Reviewed-by: Hans Holmberg > On Thu, Nov 22, 2018 at 2:47 PM Javier González wrote: >> >> 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ález >> --- >> 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 = 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 = 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 >> Picked up for 4.21.