Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2463506imu; Fri, 23 Nov 2018 09:31:45 -0800 (PST) X-Google-Smtp-Source: AJdET5f3dhPISyBUAKVDpTt+VIzdjC9khbjlL+NTuJN9Fs6l3PvUW7eC07UmxjzJi3Bior5rzGGZ X-Received: by 2002:a62:2e46:: with SMTP id u67mr16619260pfu.3.1542994305342; Fri, 23 Nov 2018 09:31:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542994305; cv=none; d=google.com; s=arc-20160816; b=vRwyeE4vZM94KoCbkucPomP5h4AGUB49Yn7CcHXPOAhhiDNfrBHUVZy8jJ2K3CMG4Y NbnI1o9aH+LlZOU/M9xce0iAtw9UaOxCsb9vbWtTJOV60yczjT+ZMyOve/n+YShVq6f7 G7PEqpCwNvhXSEqAkYINAgOpydupTk9uz2SSkOjkAErnNxuyXiy0KMUUGC23EQu13b4+ giUr3N0t9/vPz5uO7IbaOthIpX+MGarLUiXRhb2GqIQG5X9EisgzWX3N0iHi2a5CmYkM 4xswK8wAkMszDcx7LheayK4I12NM31ILMllmYzuYvFSOUidWc5mfWThZaU1cEqOi1zA0 sVqg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rWHtLTMGvL6s4MAnpD1kuO8lAzOkIuYD/LB+c3dyEeU=; b=PqJDMGlo3T5xUo5ia5IgxKKJcchB/1I9uqt1zdiJ3KKX3Q2RJ6yQ0E0Rljl1cabpHf OCWaSJpvgL6Ko9c2fuUc1kFw55mL1+P3nyTJ176j0lI/QRk0yGVtdnMv2O7D9LrRdB61 qPO7bJlE21X+++u7+dsnEGt4P9LH/S+YTMbwdopeBc9xAz8yoXwPRJMflt3U2RFFZ5oP VKf/4WlVuK+oNkPowMmCWJDxnxbyxXHIabGbXuJTkXUzU7mLCWSbIHpaM8pzOf19Cx70 lcJTw3lqBLad1YO9NDgAa7vD4rxjiDKW1dWCQOVxo6ybyIU21Dqbk+Cw+sl8jQW4hIGu lVZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=W271uKsA; 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 s12si55016979pgh.488.2018.11.23.09.31.27; Fri, 23 Nov 2018 09:31:45 -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=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=W271uKsA; 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 S2437044AbeKWA0j (ORCPT + 99 others); Thu, 22 Nov 2018 19:26:39 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:39277 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391372AbeKWA0i (ORCPT ); Thu, 22 Nov 2018 19:26:38 -0500 Received: by mail-ed1-f67.google.com with SMTP id b14so7765822edt.6 for ; Thu, 22 Nov 2018 05:47:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rWHtLTMGvL6s4MAnpD1kuO8lAzOkIuYD/LB+c3dyEeU=; b=W271uKsAdCGxoKSawAdcUCr4T6amic75JAKC6+EbnIyBAfUeq1Y0yAtJvb3g8Nlx8X vKOF8o6VTay+T8gSgC3KK0CNhHrVQJ5fBolZ1XjDtw1GwN06Ve6GqBOmR1vNEu5eUkjA 4YntVcwySShSm5C7RQhLj/QGbrtRC+/22wFNeHfAdpNLSWVna3HXrdJLvVg2i3YheCsO X6cYVyYcne6fywmEoB2JBlqKR6s3rhAkvxW1vswFG7zVC/TuPYKpgXIXlAWpdrgy/jwQ Oh9GxkZlh2DJC7mlffzznRZ0oUOx5Xo0WSDFnbCx+dNreFVHqsQoUCI3HOP+N70qAXzB nW2w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=rWHtLTMGvL6s4MAnpD1kuO8lAzOkIuYD/LB+c3dyEeU=; b=PRKNRQeBnXE7DM2wBKXeDqnZbJUQeXRMD3ii1itMS2kX3y+mvTiBVcG8sfinPYdCfb qa/RlQoS1ZYLIDXIsOUw2KnZmWfx1yxSu7a3+1IRDemcsxGORao0IAA1wFUGYuMckXg4 hY1CFNKC8NIEbTxxhPLhcLKzuSpK/ojhu+D2fyiE6YJ4g+54UnTHq65RC+rcLwtlj2sM T1kItvhRVMpfMupnJ2+YxKLUnkVti8N7Llu+fxfnilTp51bPdATXlS8ryG89DDDRFEnT 9EAQ1agyg+PZXqJ+3q/mU+hs3RUwRwV9XOn+f8ZB8XalQPPvfn3vst8wq4W92YDFsJrq oY+Q== X-Gm-Message-State: AA+aEWY5thMbExYVZMOUyNL66Vd5nZNqqmlSY9s7/nmbpTqSUY/dRprs TkNptTN3eI24g1VGz94EBNQ54A== X-Received: by 2002:a50:b4b3:: with SMTP id w48mr9483874edd.233.1542894431731; Thu, 22 Nov 2018 05:47:11 -0800 (PST) Received: from ch-wrk-javier.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id s6-v6sm14246263edh.89.2018.11.22.05.47.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Nov 2018 05:47:10 -0800 (PST) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: hans.holmberg@cnexlabs.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH] lightnvm: pblk: avoid ref warning on cache creation Date: Thu, 22 Nov 2018 14:46:50 +0100 Message-Id: <1542894410-14047-2-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542894410-14047-1-git-send-email-javier@cnexlabs.com> References: <1542894410-14047-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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