Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp576923rdh; Tue, 19 Dec 2023 07:29:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOCd9vQUgzSZMlcU4l5Oi44HuOm62TXdvl1hRb5ahldnjGTS0aaJq3quhMsQAdlmMaj5Tk X-Received: by 2002:a17:90b:384e:b0:286:6cc1:3f1c with SMTP id nl14-20020a17090b384e00b002866cc13f1cmr12173728pjb.83.1702999752250; Tue, 19 Dec 2023 07:29:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702999752; cv=none; d=google.com; s=arc-20160816; b=RDXMqoHEoCyD+y9NKB7kuCNH/Q5x5iSDJWxATFJYHMYS2kKwucL6AnD+h/DlWEswK7 0phJt/EU1p/7/f2L+bwEB+Ttsgi2FjB//K15j/pybV8mRtDr/3uuvB2UMd/AyvKfW94f ooAvszfK9b/Zmqamg8lv0KfXEW3JbKVfigM92lR/sSwDE8kCSG4IQV/fBTGTcOdTBzPl 0182/R4EntKhDaqaJL2KqjOOFb7U/Mpl3blpxQcJhfGEb2UsY6erXMjs4gKBwDWCTbGM 1OQ0iO9OAyRKW+I4CL5trXfDJjIpqUh0GTghOAguvKjyr93sSCT58X+ERKwllaIPtGMQ 3H0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=Ks7ML1uzHv8brg7fFgCUysaYMG8x8WC4+jnrx4aJ91s=; fh=9knUp49azKPIpgiJFyHt63/LPmvbAtezrIUbQBropAY=; b=lczCPoSL3/vCgHpMBzCUuiE5Aaw7ddgie6EEZJkBco4ZvOj82c55Kr1twJre1pIoNW NOq/s7Ra8SZ5IEWQb8hNRguW+sAnVPwIo0fLeJxjXHLbG4X8Y+XH2/UiGAXAs6IyDvuT TM8q3+XzshI7E+kjdK6bF/Wq+BZ/llFy9gwdg+3Fu7lbAsW8f1ZO+quqTChMsymI+hJb HjIQBK0YeGr8AYUqv1T4+R9ldnTv8rTJT7+pgm+8Y2dtpRo5l2bTV+Y+YkoZjCBXCZcV aPMbE/ggeSk4LzlOUrYet8JoRa8In4FM3f9a5DneA1s3OKzJZExSy4ExgO3aOTvpMQdT nuVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-5485-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5485-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bt1-20020a17090af00100b0028b21ac0747si1368657pjb.161.2023.12.19.07.29.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 07:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5485-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; spf=pass (google.com: domain of linux-kernel+bounces-5485-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5485-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 2FCCBB21C12 for ; Tue, 19 Dec 2023 15:28:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4451B1CA85; Tue, 19 Dec 2023 15:27:58 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 95F211CA83; Tue, 19 Dec 2023 15:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4SvgWG1tStz6K8vt; Tue, 19 Dec 2023 23:25:46 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 064A0140F80; Tue, 19 Dec 2023 23:27:30 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 19 Dec 2023 15:27:28 +0000 Date: Tue, 19 Dec 2023 15:27:26 +0000 From: Jonathan Cameron To: Vishal Verma CC: Dan Williams , Dave Jiang , Andrew Morton , "Oscar Salvador" , , , , David Hildenbrand , Dave Hansen , Huang Ying , Greg Kroah-Hartman , , Joao Martins Subject: Re: [PATCH v6 2/4] dax/bus: Use guard(device) in sysfs attribute helpers Message-ID: <20231219152726.0000228f@Huawei.com> In-Reply-To: <20231214-vv-dax_abi-v6-2-ad900d698438@intel.com> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> <20231214-vv-dax_abi-v6-2-ad900d698438@intel.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) 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-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500005.china.huawei.com (7.191.163.240) On Thu, 14 Dec 2023 22:25:27 -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. > > Cc: Joao Martins > Cc: Dan Williams > Signed-off-by: Vishal Verma Hi Vishal, A few really minor suggestions inline if you happen to be doing a v7. Either way Reviewed-by: Jonathan Cameron > > @@ -481,12 +466,9 @@ static int __free_dev_dax_id(struct dev_dax *dev_dax) > static int free_dev_dax_id(struct dev_dax *dev_dax) > { > struct device *dev = &dev_dax->dev; > - int rc; > > - device_lock(dev); > - rc = __free_dev_dax_id(dev_dax); > - device_unlock(dev); > - return rc; > + guard(device)(dev); guard(device)(&dev_dax->dev); /* Only one user now */ > + return __free_dev_dax_id(dev_dax); > } > > static int alloc_dev_dax_id(struct dev_dax *dev_dax) > @@ -908,9 +890,8 @@ static ssize_t size_show(struct device *dev, > struct dev_dax *dev_dax = to_dev_dax(dev); > unsigned long long size; > > - device_lock(dev); > + guard(device)(dev); > size = dev_dax_size(dev_dax); > - device_unlock(dev); > > return sprintf(buf, "%llu\n", size); Might as well make this guard(device)(dev); return sprintf(buf, "%llu\n", dev_dax_size(to_dev_dax(dev)); > }