From patchwork Tue Dec 11 19:16:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 10724519 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CCD2112E for ; Tue, 11 Dec 2018 19:18:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F7E229238 for ; Tue, 11 Dec 2018 19:18:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53DA029642; Tue, 11 Dec 2018 19:18:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F11F729238 for ; Tue, 11 Dec 2018 19:18:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbeLKTSD (ORCPT ); Tue, 11 Dec 2018 14:18:03 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:36681 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727151AbeLKTRU (ORCPT ); Tue, 11 Dec 2018 14:17:20 -0500 Received: by mail-lj1-f194.google.com with SMTP id g11-v6so14051522ljk.3 for ; Tue, 11 Dec 2018 11:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N4m8ctf6y9EGC+mUnRjPepFgwQACfKyscQiqNabOlRE=; b=rBzT8lAPsnGK0TXlsr01Y8QxrdVrvC3TgoTOYniq/EwFlpFaZtm3uWR4U2ZZ4gUZf1 YY/imMLZO6PiRBzq/aHIIbjZt654tnhXv9hGn3pvs3YuQlVA0pQigkVr5ARuNm+l7qAY oo+ALvHm3PNLe6/XCTXfwx1YmwtCeo6mg8IIupshdDzfa2yNeYXb+6H+CRGyDrOVznci QH2Xa4GtrTXOWl5pJh3ryGmX2IewYHRuB076yu6E50YyIUc73/1HwY7yx1sfcQ1cPfle LW20dSVtuclPz0nHzjVkDKAz+9T5eGaVxjB3c+2ZwfCIV8CsvKfAkeKfofNIFbO/j8C0 Y2uQ== 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=N4m8ctf6y9EGC+mUnRjPepFgwQACfKyscQiqNabOlRE=; b=TizyYNOdEJBOzQ70cj7yLRQ2tAuWfun5qUSoLhGYHaJpAKscOqI6SejNwHQWL+k4dp K8u40x3ZuxFkhJODbFgfLg2S7MfH0ocOIZA+Ytn8w5bJPBjeQYzMrxmfx2++Sh57t+Tr d/5CkGrwPUw82g22DWDeogbiqyeXKCLheOeSAniwVFBcjXZhNdBsiXSroq4YGojfG425 +nyh/ffO+T8Fi5XyinrUTEtGAsSybCgoalJGleH/zXkiAA2IJ9ut77mhr6NEmuZtTSYF GKKTBjH+euNj82EPqL79M2DMf8PejkZmgc7aiHFVYni/+HC6s3MCZeaukHawxwSq+sG8 zyeA== X-Gm-Message-State: AA+aEWZkGpVe5TXdfglEX9vUt9BYkkzOKFFlmmnMYjhW0s4XaVVip9IS rhmzQOaFFIg/vd6q63oBy02ROw== X-Google-Smtp-Source: AFSGD/UmjcE1RUlHxivzDdSb/DcOL0LDzhraLFh9tHdiE9UGhUbBeVYpHkg50O4saIK8mGFf5z5lXA== X-Received: by 2002:a2e:87c3:: with SMTP id v3-v6mr11380558ljj.13.1544555838714; Tue, 11 Dec 2018 11:17:18 -0800 (PST) Received: from skyninja.webspeed.dk (95-166-82-66-cable.dk.customer.tdc.net. [95.166.82.66]) by smtp.gmail.com with ESMTPSA id v64sm2764583lfa.48.2018.12.11.11.17.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 11:17:17 -0800 (PST) From: =?utf-8?q?Matias_Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Jav?= =?utf-8?q?ier_Gonz=C3=A1lez?= , =?utf-8?q?Javier_Gonz?= =?utf-8?q?=C3=A1lez?= , =?utf-8?q?Matias_Bj=C3=B8rling?= Subject: [GIT PULL 15/21] lightnvm: pblk: avoid ref warning on cache creation Date: Tue, 11 Dec 2018 20:16:21 +0100 Message-Id: <20181211191627.15542-16-mb@lightnvm.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181211191627.15542-1-mb@lightnvm.io> References: <20181211191627.15542-1-mb@lightnvm.io> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Javier González 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. Fixes: 1864de94ec9d6 "lightnvm: pblk: stop recreating global caches" Signed-off-by: Javier González Reviewed-by: Hans Holmberg Signed-off-by: Matias Bjørling --- 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 0e37104de596..72ad3e70318c 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c @@ -347,23 +347,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; }