Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6500964rdb; Thu, 14 Dec 2023 23:27:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6nIlqczrXt1iukPKvRybmcWA6NUwDdkb15SXlnladpVW1/mwru2zB0n1ojwgD/3I4kb2o X-Received: by 2002:a05:6808:3309:b0:3ba:231:cd4c with SMTP id ca9-20020a056808330900b003ba0231cd4cmr15404886oib.40.1702625277490; Thu, 14 Dec 2023 23:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702625277; cv=none; d=google.com; s=arc-20160816; b=xxEKnOAArc1a80xcWmPb0QWjD/4+YYoJ3h+0d+jJqGDLHHPfzVSZ/RbCD/C0NsT74h tTZNlw6qAjgthvVydzqqItu2/fshSiNOXwacBGvnvCw6gGtAobk6Juio4DQZOlGKajIE zOYVhM+YI5Gv7tc9XYIWORlXZ1M4U14ivP5KK86B/bGmjBE2GeyvMyIuJxU5Wxhw8tSt ciGJAKs7mnW0WN7ZUhUUN2O/A2BIwMjyK2X+tfdbkUANuNRSFGXMSitxUMPzwbxLRj88 3vOEaGHtJ3yk9F6yCEeI/bFAUArBTSZw2mk8hNPIiXd4KQDBLm7kKr5emMB71pu80BSH jfQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CYyWcykzwQp9iKpGLUsV0PhVckhUtLAAdyw22uSkF/o=; fh=5JqWIj9slb/jOoHa+9hD8Cx6KEbTPTvLhfnelrgXEOg=; b=i6ljni2q8w7EB2+VU/wu2tHbR4iKGCBF+OLYFxC8h1Xal0DrllcJK1kU9hLoFAbH7h 9/WiG9J2Cbdof1HtCtJx2Zxg2f9fT/91TV4J6xvoIO29Kf4Fdw9PUY0pi2gtR4KVrB61 nDdZIyDiNZAEmJXeKfxyNxxxZhffS2IalWQP5BrJNWKqRWjef2b63tV7+2ovGJgPrLZ1 E+Kv6X90/OaX0kvqYSwumVQNnA3gBJNkLoXESf9Y7qzhARg183IP37HTqV+0xwmYHM+E dyv4m64Jv/nn6lNnM286E8C7wq2yz0ObbbDJXF193B67XPgdf6ZcT+qXywYU4g/IPxJa eZBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2ahsi3Z1; spf=pass (google.com: domain of linux-kernel+bounces-517-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-517-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u17-20020a631411000000b005c68fce9758si12703325pgl.761.2023.12.14.23.27.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 23:27:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-517-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2ahsi3Z1; spf=pass (google.com: domain of linux-kernel+bounces-517-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-517-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C9A5BB221BF for ; Fri, 15 Dec 2023 07:27:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39E71107A6; Fri, 15 Dec 2023 07:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2ahsi3Z1" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43985101F2; Fri, 15 Dec 2023 07:27:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 165FBC433C8; Fri, 15 Dec 2023 07:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1702625265; bh=VYMxaVjM6jwKEDyy8TIhlqese/qfmw3BV5SnzVRzTIs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=2ahsi3Z15c5odISV0SkywBPiGig9wTvX0Ka/UkXIVW+H/rOvFx2LjenR8JvmmJaVW x/G8ctfg3uXuIWCVHQR+RDiIob8i7L/jkYvZ9TE+oVm5lMsWZUv+uYgILI0fjzBbL5 biGDqji/jICTM+7jBY/fqSfO35D/rROcaFI/wuJE= Date: Fri, 15 Dec 2023 08:27:42 +0100 From: Greg Kroah-Hartman To: Vishal Verma Cc: Dan Williams , Dave Jiang , Andrew Morton , Oscar Salvador , linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, David Hildenbrand , Dave Hansen , Huang Ying , linux-mm@kvack.org, Joao Martins Subject: Re: [PATCH v6 2/4] dax/bus: Use guard(device) in sysfs attribute helpers Message-ID: <2023121515-litigate-finished-76dd@gregkh> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> <20231214-vv-dax_abi-v6-2-ad900d698438@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214-vv-dax_abi-v6-2-ad900d698438@intel.com> On Thu, Dec 14, 2023 at 10:25:27PM -0700, Vishal Verma wrote: > Use the guard(device) macro to lock a 'struct device', and unlock it > automatically when going out of scope using Scope Based Resource > Management semantics. A lot of the sysfs attribute writes in > drivers/dax/bus.c benefit from a cleanup using these, so change these > where applicable. Wait, why are you needing to call device_lock() at all here? Why is dax special in needing this when no other subsystem requires it? > > Cc: Joao Martins > Cc: Dan Williams > Signed-off-by: Vishal Verma > --- > drivers/dax/bus.c | 143 ++++++++++++++++++++++-------------------------------- > 1 file changed, 59 insertions(+), 84 deletions(-) > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > index 1ff1ab5fa105..6226de131d17 100644 > --- a/drivers/dax/bus.c > +++ b/drivers/dax/bus.c > @@ -294,13 +294,10 @@ static ssize_t available_size_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > struct dax_region *dax_region = dev_get_drvdata(dev); > - unsigned long long size; > > - device_lock(dev); > - size = dax_region_avail_size(dax_region); > - device_unlock(dev); > + guard(device)(dev); You have a valid device here, why are you locking it? How can it go away? And if it can, shouldn't you have a local lock for it, and not abuse the driver core lock? > > - return sprintf(buf, "%llu\n", size); > + return sprintf(buf, "%llu\n", dax_region_avail_size(dax_region)); sysfs_emit() everywhere please. But again, the issue is "why do you need a lock"? thanks, greg k-h