From nobody Wed Dec 17 20:58:42 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 33AA91FDE19 for ; Fri, 14 Mar 2025 11:45:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952743; cv=none; b=LnFyC/NnS3kMsUPYD4eoqUCxI96XLzW9yVHk2W4svJrxlACG69GON66kUlB+h7n1SCgnBzREh9VAtK9r1/qbotE1QFvgbBdUXuBTFi5M4LXqPceryAxXMb4fbywoNDN3q/sDwCIAwCrOpp3UjeOkiA/YFUHGsvm0LwrY7fSWRp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952743; c=relaxed/simple; bh=JfkqTO4XQAFJC3G9pkhdVDCoq+KaJL7gqWaGsD8ehVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ev+vfs5PjWqx2U9mD141muRqo9YW+bJYQTplU/aQHa/Wa0ueMkBf12A6FoLh+jl5wFvBYq/m+/g3oqF3nqcC04/Xzf6QEexxK3n5PyyLS+C3u8l6/ljmbNyD/I1OVwTU3Zfw8WEi7wPydHeHRdb+PmzA8nHONCdSwi29lo+gw30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=aPok21Cp; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="aPok21Cp" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52E9d8D9005804; Fri, 14 Mar 2025 11:45:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=XxU5XP2xQsKie4KRP nlKDhPgga75rXA+r7mJnNP2BIg=; b=aPok21CpJprGHm/w34C5YGH9cufkq/pCl 0DjQW28yt7zFX4DfaC/FJOw3KUT3hf1Jip32rUrjvzhjchxB28ZJbf3dSTxPB2w/ 8+AmMdFUAD2qB11Kf4VJJWTInOg/Dl94Qv65RoKsZ7KmzbZ0TrDqtvBc+NFY8bej PwuBMcfC+98i8ih7tzHIfKgv+UGz74oLo187Pc3GIX76TKBu8GDfLHga11ww0Y9e FunRhs66cNReq1ly3UlSOWt4EEznLVsMYtZT3xO836KDMDHLxmOEjYrkkAoT+B5H hiS871KV2Js05xtg6l1QBee+cIBCmk+WHyyFeHvcijmEpBVa9CZPQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6s5b9mk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:27 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52EBe7ob016034; Fri, 14 Mar 2025 11:45:27 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6s5b9mh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:27 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52E9334q007468; Fri, 14 Mar 2025 11:45:26 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 45atsrepht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:26 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52EBjMfZ45023522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Mar 2025 11:45:22 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 739A320040; Fri, 14 Mar 2025 11:45:22 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2909F2004B; Fri, 14 Mar 2025 11:45:19 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.22.126]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Mar 2025 11:45:18 +0000 (GMT) From: Shrikanth Hegde To: maddy@linux.ibm.com, linuxppc-dev@lists.ozlabs.org Cc: sshegde@linux.ibm.com, npiggin@gmail.com, christophe.leroy@csgroup.eu, mpe@ellerman.id.au, peterz@infradead.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, mahesh@linux.ibm.com, oohall@gmail.com, hbathini@linux.ibm.com, dhowells@redhat.com, haren@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] powerpc: eeh: use lock guard for mutex Date: Fri, 14 Mar 2025 17:14:57 +0530 Message-ID: <20250314114502.2083434-2-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250314114502.2083434-1-sshegde@linux.ibm.com> References: <20250314114502.2083434-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UturKL8y2FZj2RR3JkdIyvvHbWZN1fG9 X-Proofpoint-ORIG-GUID: kqQps5Cxte0KhNP6-ur22Y3F7FQeCl-p X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-14_04,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=808 clxscore=1015 impostorscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503140091 Content-Type: text/plain; charset="utf-8" use guard(mutex) for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u Signed-off-by: Shrikanth Hegde Reviewed-by: Srikar Dronamraju --- arch/powerpc/kernel/eeh.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c index 83fe99861eb1..929474c0ec77 100644 --- a/arch/powerpc/kernel/eeh.c +++ b/arch/powerpc/kernel/eeh.c @@ -1208,16 +1208,16 @@ int eeh_dev_open(struct pci_dev *pdev) struct eeh_dev *edev; int ret =3D -ENODEV; =20 - mutex_lock(&eeh_dev_mutex); + guard(mutex)(&eeh_dev_mutex); =20 /* No PCI device ? */ if (!pdev) - goto out; + return ret; =20 /* No EEH device or PE ? */ edev =3D pci_dev_to_eeh_dev(pdev); if (!edev || !edev->pe) - goto out; + return ret; =20 /* * The PE might have been put into frozen state, but we @@ -1227,16 +1227,12 @@ int eeh_dev_open(struct pci_dev *pdev) */ ret =3D eeh_pe_change_owner(edev->pe); if (ret) - goto out; + return ret; =20 /* Increase PE's pass through count */ atomic_inc(&edev->pe->pass_dev_cnt); - mutex_unlock(&eeh_dev_mutex); =20 return 0; -out: - mutex_unlock(&eeh_dev_mutex); - return ret; } EXPORT_SYMBOL_GPL(eeh_dev_open); =20 @@ -1252,22 +1248,20 @@ void eeh_dev_release(struct pci_dev *pdev) { struct eeh_dev *edev; =20 - mutex_lock(&eeh_dev_mutex); + guard(mutex)(&eeh_dev_mutex); =20 /* No PCI device ? */ if (!pdev) - goto out; + return; =20 /* No EEH device ? */ edev =3D pci_dev_to_eeh_dev(pdev); if (!edev || !edev->pe || !eeh_pe_passed(edev->pe)) - goto out; + return; =20 /* Decrease PE's pass through count */ WARN_ON(atomic_dec_if_positive(&edev->pe->pass_dev_cnt) < 0); eeh_pe_change_owner(edev->pe); -out: - mutex_unlock(&eeh_dev_mutex); } EXPORT_SYMBOL(eeh_dev_release); =20 --=20 2.39.3 From nobody Wed Dec 17 20:58:42 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 90A121F3BB6 for ; Fri, 14 Mar 2025 11:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952748; cv=none; b=Wei3+sq4H17zu+ettpSiaBQhU7Z4GghuySoxg/4wHz8xkwcy/cO2J4m500SBjZFwcm6BMrwO2oWWpyhKWgD5oDviRU4NjQYWR4/kLva/+ROANNgKglQz6qBiY7ltrCdW6IQFlrs1nMmumdWZBxXQvamnbyBN3DSYvEjufxOGcL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952748; c=relaxed/simple; bh=eI04HedwGrj5qLVlTsC440XRtGlC/SclPwlxp94Ld2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kiB93EgZgxTLliBgY9aJrG9adjPZQ/IlGSp4ZHwj04H0f3J3LyCCwzRrnD3FwGmDVuip/wdP+XLehlrO3j+OQueQUkCOnfg+14dRAN4JbqwdZhMSdIeZuY7td2bI6o2oIm83dbgtmM4FhFVLMjYn2NGdr14LU8R4+qjkkONgDKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=AZ19pTMQ; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="AZ19pTMQ" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52EAOCbE032132; Fri, 14 Mar 2025 11:45:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=rHiuokT753NlluXTP eZq8TFHySwH4S01ZogXJ3+Y+w0=; b=AZ19pTMQH/XI/IGVag7vo/SyabbKxdnsm nZhOyPrCrIwjumkiyh3kh7lmGL4hr2oKMIgPeyiGXVgf81vbWykyWXpuyU2LQwj8 YWtt7ONymUnDQJvp2Lgy9thOe+FX6qWApo8h0Pgrvr3RMSvn8Uz9jX0GlH28KR3E fWzFoDl5WJsFjeGrYPF9zAfSFjV+9qjSpnieEEa90Yz4/G2AUYZ7zDTSam9zU+xC Cjf0cpYnF5sW2FSbdef4uGhAg6glHzj0xElbS9OaGXtKcQyerfwAEg6L+Wd0FlWH uMW9kyWxcPmWJzf73MJdmH5woon1Dpov5e6SUTWl9CwRYRWgv8hMA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6hpudk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:31 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52EBjVVp019267; Fri, 14 Mar 2025 11:45:31 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6hpudk4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:31 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52E91RiA012314; Fri, 14 Mar 2025 11:45:30 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 45atsrppnt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:30 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52EBjQgC39977448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Mar 2025 11:45:27 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D58222004B; Fri, 14 Mar 2025 11:45:26 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9041720040; Fri, 14 Mar 2025 11:45:23 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.22.126]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Mar 2025 11:45:23 +0000 (GMT) From: Shrikanth Hegde To: maddy@linux.ibm.com, linuxppc-dev@lists.ozlabs.org Cc: sshegde@linux.ibm.com, npiggin@gmail.com, christophe.leroy@csgroup.eu, mpe@ellerman.id.au, peterz@infradead.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, mahesh@linux.ibm.com, oohall@gmail.com, hbathini@linux.ibm.com, dhowells@redhat.com, haren@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] powerpc: rtas: use lock guard for mutex Date: Fri, 14 Mar 2025 17:14:58 +0530 Message-ID: <20250314114502.2083434-3-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250314114502.2083434-1-sshegde@linux.ibm.com> References: <20250314114502.2083434-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: o69mgQckJtTmYwcFHYOPw61DoABOXmSD X-Proofpoint-ORIG-GUID: 6l5AajEu6YpFFXEg9XVbV0la8hDUIWG- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-14_04,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503140091 Content-Type: text/plain; charset="utf-8" use guard(mutex) for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u Signed-off-by: Shrikanth Hegde Reviewed-by: Srikar Dronamraju --- arch/powerpc/kernel/rtas_flash.c | 64 ++++++++++---------------------- 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_fl= ash.c index 5407024881e5..583dc16e9d3c 100644 --- a/arch/powerpc/kernel/rtas_flash.c +++ b/arch/powerpc/kernel/rtas_flash.c @@ -312,13 +312,13 @@ static ssize_t rtas_flash_write(struct file *file, co= nst char __user *buffer, { struct rtas_update_flash_t *const uf =3D &rtas_update_flash_data; char *p; - int next_free, rc; + int next_free; struct flash_block_list *fl; =20 - mutex_lock(&rtas_update_flash_mutex); + guard(mutex)(&rtas_update_flash_mutex); =20 if (uf->status =3D=3D FLASH_AUTH || count =3D=3D 0) - goto out; /* discard data */ + return count; /* discard data */ =20 /* In the case that the image is not ready for flashing, the memory * allocated for the block list will be freed upon the release of the=20 @@ -327,7 +327,7 @@ static ssize_t rtas_flash_write(struct file *file, cons= t char __user *buffer, if (uf->flist =3D=3D NULL) { uf->flist =3D kmem_cache_zalloc(flash_block_cache, GFP_KERNEL); if (!uf->flist) - goto nomem; + return -ENOMEM; } =20 fl =3D uf->flist; @@ -338,7 +338,7 @@ static ssize_t rtas_flash_write(struct file *file, cons= t char __user *buffer, /* Need to allocate another block_list */ fl->next =3D kmem_cache_zalloc(flash_block_cache, GFP_KERNEL); if (!fl->next) - goto nomem; + return -ENOMEM; fl =3D fl->next; next_free =3D 0; } @@ -347,25 +347,17 @@ static ssize_t rtas_flash_write(struct file *file, co= nst char __user *buffer, count =3D RTAS_BLK_SIZE; p =3D kmem_cache_zalloc(flash_block_cache, GFP_KERNEL); if (!p) - goto nomem; + return -ENOMEM; =09 if(copy_from_user(p, buffer, count)) { kmem_cache_free(flash_block_cache, p); - rc =3D -EFAULT; - goto error; + return -EFAULT; } fl->blocks[next_free].data =3D p; fl->blocks[next_free].length =3D count; fl->num_blocks++; -out: - mutex_unlock(&rtas_update_flash_mutex); - return count; =20 -nomem: - rc =3D -ENOMEM; -error: - mutex_unlock(&rtas_update_flash_mutex); - return rc; + return count; } =20 /* @@ -405,19 +397,18 @@ static ssize_t manage_flash_write(struct file *file, = const char __user *buf, static const char reject_str[] =3D "0"; static const char commit_str[] =3D "1"; char stkbuf[10]; - int op, rc; + int op; =20 - mutex_lock(&rtas_manage_flash_mutex); + guard(mutex)(&rtas_manage_flash_mutex); =20 if ((args_buf->status =3D=3D MANAGE_AUTH) || (count =3D=3D 0)) - goto out; + return count; =09 op =3D -1; if (buf) { if (count > 9) count =3D 9; - rc =3D -EFAULT; if (copy_from_user (stkbuf, buf, count)) - goto error; + return -EFAULT; if (strncmp(stkbuf, reject_str, strlen(reject_str)) =3D=3D 0)=20 op =3D RTAS_REJECT_TMP_IMG; else if (strncmp(stkbuf, commit_str, strlen(commit_str)) =3D=3D 0)=20 @@ -425,18 +416,11 @@ static ssize_t manage_flash_write(struct file *file, = const char __user *buf, } =09 if (op =3D=3D -1) { /* buf is empty, or contains invalid string */ - rc =3D -EINVAL; - goto error; + return -EINVAL; } =20 manage_flash(args_buf, op); -out: - mutex_unlock(&rtas_manage_flash_mutex); return count; - -error: - mutex_unlock(&rtas_manage_flash_mutex); - return rc; } =20 /* @@ -499,16 +483,14 @@ static ssize_t validate_flash_write(struct file *file= , const char __user *buf, { struct rtas_validate_flash_t *const args_buf =3D &rtas_validate_flash_data; - int rc; =20 - mutex_lock(&rtas_validate_flash_mutex); + guard(mutex)(&rtas_validate_flash_mutex); =20 /* We are only interested in the first 4K of the * candidate image */ if ((*off >=3D VALIDATE_BUF_SIZE) ||=20 (args_buf->status =3D=3D VALIDATE_AUTH)) { *off +=3D count; - mutex_unlock(&rtas_validate_flash_mutex); return count; } =20 @@ -519,20 +501,14 @@ static ssize_t validate_flash_write(struct file *file= , const char __user *buf, args_buf->status =3D VALIDATE_INCOMPLETE; } =20 - if (!access_ok(buf, count)) { - rc =3D -EFAULT; - goto done; - } - if (copy_from_user(args_buf->buf + *off, buf, count)) { - rc =3D -EFAULT; - goto done; - } + if (!access_ok(buf, count)) + return -EFAULT; + + if (copy_from_user(args_buf->buf + *off, buf, count)) + return -EFAULT; =20 *off +=3D count; - rc =3D count; -done: - mutex_unlock(&rtas_validate_flash_mutex); - return rc; + return count; } =20 static int validate_flash_release(struct inode *inode, struct file *file) --=20 2.39.3 From nobody Wed Dec 17 20:58:42 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 78AEC1FDE27 for ; Fri, 14 Mar 2025 11:45:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952754; cv=none; b=nyGu/wpC5foYSpltqKIwH/gZfErHSSX4dK+r6WmbvJaXODt6Y6Sc7H82b6wtufUYh368ye7KISyP/+UTVon13rRB2+9OHCPASAE2bxOKyRsN4VPhp0vVuKPFSOz0H9/Z2n5UdaZhmcfRi8e8DYVEZSWPiu/k8oNaOKfESGs+7S4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952754; c=relaxed/simple; bh=Hu8sULZie0oMT9SIO4X87dt7d8AORtAxqgYZcICW698=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OxhJBAJCFOYAXK5pbUtpTSK/4J/X4nkPZTYdw8jgOY8yJ4kR5b12zqDbGuhfYhAiEoh6a2qFi5v57VTH4MqGO9zO/FsrF6jUiZER6kfCstLm+U1/JcqwVfFWB15uS1h0qFtA/Finx3OI+J5XQ3S2H67+0JknpA2P6zwMEcGCxPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=BM+3PSS6; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="BM+3PSS6" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52EB0m9O001939; Fri, 14 Mar 2025 11:45:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=Des5ngxLQ5668Zie0 APp79mBo5Tmu7ME/Ak7Q/J8mj8=; b=BM+3PSS664XtoE3jB/+HGfpW4UqBF6PeC fLr8R8ctsOPHpfZspnyyIzRrzTR1Q4WpuFqzphGc+FSNs+G+G8Nl0r7v1stURQW1 592QObhVja+xezF2+b3Z94DbPUR6sh8OBCPiCpiw/Vh38ElZQrZg2c1lDDNc0DIu Nj+orYNMkUHbxfKFZhQq487zmPbmEvbqM4Y1Ag76HQERGpAcEhut9AtDs9dg0cp+ wJsZ9jguULTL9b8fNaM2HTj9Ws1eV4Y6yVrxxBosVFH5lwlYlfYQgvsH4/fEtp40 ExHIQxGCR3/6JJekQNhS+CL5vYxdEHhcTnUCs7KkMq+8Kc0GKOEQg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6hpudkh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:36 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52EBiRqg016764; Fri, 14 Mar 2025 11:45:35 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6hpudkf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:35 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52E8WSE4015357; Fri, 14 Mar 2025 11:45:34 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atsppq7e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:34 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52EBjVUA34865804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Mar 2025 11:45:31 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 410862004E; Fri, 14 Mar 2025 11:45:31 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC6722004B; Fri, 14 Mar 2025 11:45:27 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.22.126]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Mar 2025 11:45:27 +0000 (GMT) From: Shrikanth Hegde To: maddy@linux.ibm.com, linuxppc-dev@lists.ozlabs.org Cc: sshegde@linux.ibm.com, npiggin@gmail.com, christophe.leroy@csgroup.eu, mpe@ellerman.id.au, peterz@infradead.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, mahesh@linux.ibm.com, oohall@gmail.com, hbathini@linux.ibm.com, dhowells@redhat.com, haren@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] powerpc: fadump: use lock guard for mutex Date: Fri, 14 Mar 2025 17:14:59 +0530 Message-ID: <20250314114502.2083434-4-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250314114502.2083434-1-sshegde@linux.ibm.com> References: <20250314114502.2083434-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Jh4LPkSVlRClFZBVYA-cGyYUB2sB5r6N X-Proofpoint-ORIG-GUID: SeRbKrqwDoY0QVWHWlC76RIQOVxC2jGl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-14_04,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 adultscore=0 mlxlogscore=711 malwarescore=0 bulkscore=0 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503140091 Content-Type: text/plain; charset="utf-8" use scoped_guard for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u Signed-off-by: Shrikanth Hegde Reviewed-by: Srikar Dronamraju --- arch/powerpc/kernel/fadump.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index 4b371c738213..fc6c5275811e 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -1374,15 +1374,12 @@ static void fadump_free_elfcorehdr_buf(void) =20 static void fadump_invalidate_release_mem(void) { - mutex_lock(&fadump_mutex); - if (!fw_dump.dump_active) { - mutex_unlock(&fadump_mutex); - return; + scoped_guard(mutex, &fadump_mutex) { + if (!fw_dump.dump_active) + return; + fadump_cleanup(); } =20 - fadump_cleanup(); - mutex_unlock(&fadump_mutex); - fadump_free_elfcorehdr_buf(); fadump_release_memory(fw_dump.boot_mem_top, memblock_end_of_DRAM()); fadump_free_cpu_notes_buf(); --=20 2.39.3 From nobody Wed Dec 17 20:58:42 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 418261FECA5 for ; Fri, 14 Mar 2025 11:45:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952757; cv=none; b=SKiPgTb62CZmaSZW/DQprZ2jNSu4dlXRgY2UEZyMGn7yFfeNzniU130RZ8pfXSMHitfB3MFIDF+4QdSLIMqFOIxofR/SQ1sg6BsQk+KN/2f5rjRy+WZ8ODg08JKQapfyWnWbYfoGxnnWqzRwXiWHdtyRXqhMXZz6+ADtSos38gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952757; c=relaxed/simple; bh=Tvv12iTSy9n5LNJOna+hsoiAWlL1kBwqIdQdhXIXbYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XjKdK+7N49G8CidkcidOXuH1tawDZTi+LEbcZUnWAG0Cvbok3MXWr8UMzglMUrhcg9IA9sta26gq9nqmKROTJd9KBUJPlpyMsx8UXbxN37H+ExytTta6fwoNguxuidcntn5PXLbr4AjqwHfuISQCXzzSoy9ZED7IjXaFEig500w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=FnwmlJGh; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="FnwmlJGh" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52EBN1D6013877; Fri, 14 Mar 2025 11:45:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=WHKm3ExNyDDNq83Qq NAnyUo4+cD7TyY5b8WeyJnoQkA=; b=FnwmlJGh05XY1E7uy1yfmgmMmf4mWYv6E wqZbPXDB5ZR+FqcvkVw7qCdjorKyIvnKztEr9Kl9Xdx40bMjN7pMqa3DceacQF6F rngw1PgGPQ8m65I3F5CfMNy1UuIpOH4m377aLoxXANTrl7QgAZVIP4C/iT3FNilD U4MKl6ciNlYZ4sDLokoow0ebqgpFxtV5GUhvqSmQ9/x1OEPW+0L/M3ayk5YLiNzY 9JGOEngvyUXICFzM0PTILzfvV+3rWlwZ0++/5gHXxRbE7+JzMu7s5mfjGR5n1u+f eYg5Glg6W0bmwgNCucKmQXdU+JmkvnZKcXt2t30a5rXl+U5MBZTkg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6k03cf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:40 +0000 (GMT) Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52EBhTWw027336; Fri, 14 Mar 2025 11:45:40 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6k03cex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:39 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52E8x6BH003131; Fri, 14 Mar 2025 11:45:39 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atstxqd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:39 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52EBjZxF35848936 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Mar 2025 11:45:35 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A84EC20043; Fri, 14 Mar 2025 11:45:35 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E87820040; Fri, 14 Mar 2025 11:45:32 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.22.126]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Mar 2025 11:45:32 +0000 (GMT) From: Shrikanth Hegde To: maddy@linux.ibm.com, linuxppc-dev@lists.ozlabs.org Cc: sshegde@linux.ibm.com, npiggin@gmail.com, christophe.leroy@csgroup.eu, mpe@ellerman.id.au, peterz@infradead.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, mahesh@linux.ibm.com, oohall@gmail.com, hbathini@linux.ibm.com, dhowells@redhat.com, haren@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] powerpc: book3s: vas: use lock guard for mutex Date: Fri, 14 Mar 2025 17:15:00 +0530 Message-ID: <20250314114502.2083434-5-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250314114502.2083434-1-sshegde@linux.ibm.com> References: <20250314114502.2083434-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: SGiKbM8qQBl08NH7jKOTAr6hNJKZ6cZB X-Proofpoint-ORIG-GUID: j-QpR_LFl5mFR3pqyzQu-3Wgu00abwwB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-14_04,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=795 priorityscore=1501 impostorscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 adultscore=0 spamscore=0 mlxscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503140091 Content-Type: text/plain; charset="utf-8" use lock guards for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u This shows the use of both guard and scoped_guard Signed-off-by: Shrikanth Hegde Reviewed-by: Srikar Dronamraju --- arch/powerpc/platforms/book3s/vas-api.c | 32 ++++++++++--------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/platforms/book3s/vas-api.c b/arch/powerpc/platfor= ms/book3s/vas-api.c index 0b6365d85d11..d7462c16d828 100644 --- a/arch/powerpc/platforms/book3s/vas-api.c +++ b/arch/powerpc/platforms/book3s/vas-api.c @@ -425,23 +425,22 @@ static vm_fault_t vas_mmap_fault(struct vm_fault *vmf) return VM_FAULT_SIGBUS; } =20 - mutex_lock(&txwin->task_ref.mmap_mutex); /* * The window may be inactive due to lost credit (Ex: core * removal with DLPAR). If the window is active again when * the credit is available, map the new paste address at the * window virtual address. */ - if (txwin->status =3D=3D VAS_WIN_ACTIVE) { - paste_addr =3D cp_inst->coproc->vops->paste_addr(txwin); - if (paste_addr) { - fault =3D vmf_insert_pfn(vma, vma->vm_start, - (paste_addr >> PAGE_SHIFT)); - mutex_unlock(&txwin->task_ref.mmap_mutex); - return fault; + scoped_guard(mutex, &txwin->task_ref.mmap_mutex) { + if (txwin->status =3D=3D VAS_WIN_ACTIVE) { + paste_addr =3D cp_inst->coproc->vops->paste_addr(txwin); + if (paste_addr) { + fault =3D vmf_insert_pfn(vma, vma->vm_start, + (paste_addr >> PAGE_SHIFT)); + return fault; + } } } - mutex_unlock(&txwin->task_ref.mmap_mutex); =20 /* * Received this fault due to closing the actual window. @@ -494,9 +493,8 @@ static void vas_mmap_close(struct vm_area_struct *vma) return; } =20 - mutex_lock(&txwin->task_ref.mmap_mutex); - txwin->task_ref.vma =3D NULL; - mutex_unlock(&txwin->task_ref.mmap_mutex); + scoped_guard(mutex, &txwin->task_ref.mmap_mutex) + txwin->task_ref.vma =3D NULL; } =20 static const struct vm_operations_struct vas_vm_ops =3D { @@ -543,18 +541,16 @@ static int coproc_mmap(struct file *fp, struct vm_are= a_struct *vma) * close/open event and allows mmap() only when the window is * active. */ - mutex_lock(&txwin->task_ref.mmap_mutex); + guard(mutex)(&txwin->task_ref.mmap_mutex); if (txwin->status !=3D VAS_WIN_ACTIVE) { pr_err("Window is not active\n"); - rc =3D -EACCES; - goto out; + return -EACCES; } =20 paste_addr =3D cp_inst->coproc->vops->paste_addr(txwin); if (!paste_addr) { pr_err("Window paste address failed\n"); - rc =3D -EINVAL; - goto out; + return -EINVAL; } =20 pfn =3D paste_addr >> PAGE_SHIFT; @@ -574,8 +570,6 @@ static int coproc_mmap(struct file *fp, struct vm_area_= struct *vma) txwin->task_ref.vma =3D vma; vma->vm_ops =3D &vas_vm_ops; =20 -out: - mutex_unlock(&txwin->task_ref.mmap_mutex); return rc; } =20 --=20 2.39.3 From nobody Wed Dec 17 20:58:42 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 D17FF1FECA9 for ; Fri, 14 Mar 2025 11:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952761; cv=none; b=IzDtNGvkCqDLoVihdlYKNtNHAh+Gugikdu83rqK8yMcTP4t69gMZmn4SxV20rPcW8F5i50yOBI9rtTd/pDdr63CwNiuOZ7uB1HQTZ4xdiqn+7eZ7yiVuC718A/EBGeog5I5ohmcPJQEIdTlgaa6OPvutL94JlTcPqTLxRu7mE9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952761; c=relaxed/simple; bh=ruBEfoMwzZH39i3/UnFKZ+4dD1O0Kgi8BMe8Do6Tncc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aROyZou3xiqV8Q3Q2Zni8PWIE+w5xTKlFvDm3aG465ptFfq/J+JFzaLozjaPHRZ2PBYl38XzjK1dEteMlXeOK9XzUDVW/cePwZROsx3e3s14Vpg6gfnjGZhtbDLNfRsEOu8rlpqWJ4gyT0rujhw4KxbBbYZhGQFkBKPrxN4i1lo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=NxJi0e2r; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="NxJi0e2r" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52EATY6f005811; Fri, 14 Mar 2025 11:45:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=Slm+QcWnMt+vSRjRU 5hHB8Yv0leGrSO3vsQoycHpWIg=; b=NxJi0e2rEoO6cLqSbTanr0QpsgyamTJcW aOHTQvM3rlUHYXnAyxjtufDoPUH4vno13vMlxtGBm14XnViPT1lS3gxSgrkO2f9G DxiC+WDtBMOsrJpAzbL2T9IdMYoCgrSmXCu3mr9rSkXvi9Khj95SbFUi6Q0E7DBa isf+apfW5JPa/eaEoxJGO7/bQ165k6voPN579DRtIbPr4KuL1zm24r6ghfvDNoDB u1pcdbV2f0zzq87/j/odEqFoOJpM4XA/vf70lep4HUvX6N7fCtoBK9XkOKSmUtym oQw+KsGzmxeXIDqdzTh5Uusr4fjaEd6gvSAKNI3nSBOR7jepP3W6g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6s5b9nd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:44 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52EBUH2k024757; Fri, 14 Mar 2025 11:45:44 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45c6s5b9n9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:44 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52E93At9026021; Fri, 14 Mar 2025 11:45:43 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atspprh0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:43 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52EBjeh940894912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Mar 2025 11:45:40 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1AF9920040; Fri, 14 Mar 2025 11:45:40 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C7A422004B; Fri, 14 Mar 2025 11:45:36 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.22.126]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Mar 2025 11:45:36 +0000 (GMT) From: Shrikanth Hegde To: maddy@linux.ibm.com, linuxppc-dev@lists.ozlabs.org Cc: sshegde@linux.ibm.com, npiggin@gmail.com, christophe.leroy@csgroup.eu, mpe@ellerman.id.au, peterz@infradead.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, mahesh@linux.ibm.com, oohall@gmail.com, hbathini@linux.ibm.com, dhowells@redhat.com, haren@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] powerpc: powernv: ocxl: use lock guard for mutex Date: Fri, 14 Mar 2025 17:15:01 +0530 Message-ID: <20250314114502.2083434-6-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250314114502.2083434-1-sshegde@linux.ibm.com> References: <20250314114502.2083434-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: WDlYtrigkizWK_eI8Sa89vGVzvko9BVd X-Proofpoint-ORIG-GUID: 0lY6FIU1w1S_4lE9ReG44QVTstmVYxWc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-14_04,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=826 clxscore=1015 impostorscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503140091 Content-Type: text/plain; charset="utf-8" use guard(mutex) for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u Signed-off-by: Shrikanth Hegde Acked-by: Andrew Donnellan Reviewed-by: Srikar Dronamraju --- arch/powerpc/platforms/powernv/ocxl.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/platforms/powernv/ocxl.c b/arch/powerpc/platforms= /powernv/ocxl.c index 64a9c7125c29..f8139948348e 100644 --- a/arch/powerpc/platforms/powernv/ocxl.c +++ b/arch/powerpc/platforms/powernv/ocxl.c @@ -172,12 +172,11 @@ static void pnv_ocxl_fixup_actag(struct pci_dev *dev) if (phb->type !=3D PNV_PHB_NPU_OCAPI) return; =20 - mutex_lock(&links_list_lock); + guard(mutex)(&links_list_lock); =20 link =3D find_link(dev); if (!link) { dev_warn(&dev->dev, "couldn't update actag information\n"); - mutex_unlock(&links_list_lock); return; } =20 @@ -206,7 +205,6 @@ static void pnv_ocxl_fixup_actag(struct pci_dev *dev) dev_dbg(&dev->dev, "total actags for function: %d\n", link->fn_desired_actags[PCI_FUNC(dev->devfn)]); =20 - mutex_unlock(&links_list_lock); } DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pnv_ocxl_fixup_actag); =20 @@ -253,12 +251,11 @@ int pnv_ocxl_get_actag(struct pci_dev *dev, u16 *base= , u16 *enabled, { struct npu_link *link; =20 - mutex_lock(&links_list_lock); + guard(mutex)(&links_list_lock); =20 link =3D find_link(dev); if (!link) { dev_err(&dev->dev, "actag information not found\n"); - mutex_unlock(&links_list_lock); return -ENODEV; } /* @@ -274,7 +271,6 @@ int pnv_ocxl_get_actag(struct pci_dev *dev, u16 *base, = u16 *enabled, *enabled =3D link->fn_actags[PCI_FUNC(dev->devfn)].count; *supported =3D link->fn_desired_actags[PCI_FUNC(dev->devfn)]; =20 - mutex_unlock(&links_list_lock); return 0; } EXPORT_SYMBOL_GPL(pnv_ocxl_get_actag); @@ -293,12 +289,11 @@ int pnv_ocxl_get_pasid_count(struct pci_dev *dev, int= *count) * * We only support one AFU-carrying function for now. */ - mutex_lock(&links_list_lock); + guard(mutex)(&links_list_lock); =20 link =3D find_link(dev); if (!link) { dev_err(&dev->dev, "actag information not found\n"); - mutex_unlock(&links_list_lock); return -ENODEV; } =20 @@ -309,7 +304,6 @@ int pnv_ocxl_get_pasid_count(struct pci_dev *dev, int *= count) break; } =20 - mutex_unlock(&links_list_lock); dev_dbg(&dev->dev, "%d PASIDs available for function\n", rc ? 0 : *count); return rc; --=20 2.39.3 From nobody Wed Dec 17 20:58:42 2025 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 8301D1F8ADD for ; Fri, 14 Mar 2025 11:46:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952768; cv=none; b=Bq99/GyhDGzgUFiM1/f+BRGKGelLwd47c0/En69huTm5SV/Fj3y7k13LSoAopbJwdpk8QqErrtbwbCbxGOcC8d61A46//wvnv3/d/R5oO7GMgGA9eVoxocA+cn+TcfGSwThUphoBzav9b/brBn5HtZ4AtiqVYHszMI+9oVGw/fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741952768; c=relaxed/simple; bh=1DkS2cn25IZOsOqgB34SeuFVQyVPdVpZ8rt0xOcBNOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UJmcOnaKGXHKNPIysLJWNOtVCaJhB/S4NZ5b16TnI6ZNhT26R3vq9aDocNCGM+DU7bv8EOa+ffFoGrNbsC4Cy6tLfZfvmqkeTOZO85/9o1SUCvY7SVRnaYUpspwO0hMorXFPuMe2alTQlLdCe5crui4Lv0jEo48oPsoNV+VPd7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=WT1ElFHM; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="WT1ElFHM" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52EALlGJ031989; Fri, 14 Mar 2025 11:45:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=rqd8nApZfIj14eDIu EBmgblnXR/j8d+uZ5j9bQDSyx8=; b=WT1ElFHMDX/7O286czrd6OaiTWHnQsAO0 0m5xP3uJRj0YPgkdEVtOSoDm1LtR3RAAWASZwvbTbHZ0gjQl6zYAPy0GYNrf+GGC toQqDNjRnkeizCCxEWFX4gCunQcAGiGv/3rq2rUV3G+kwDNlFTYM5oKYJn+qnFPs TDTSZWQ4BxNIK3A7g/Hgp4CrebfALQiTFPLTuda95PuC5ZpzB6EpSPf+ZgFLPtz3 UalrHDvJFA7+eLK3vZ0YUa6coclJJz3LIGlh8buA9qaiUM0pzKX9EZDNc5r08ilU p/2MYEBJMWttRSdZ0AqGq5JNLKdoBhzhevY+gftJUncQ04/OBGQlQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45byd8x1ma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:49 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52EBaCqa009227; Fri, 14 Mar 2025 11:45:49 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45byd8x1m8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:49 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52E8KXtN007406; Fri, 14 Mar 2025 11:45:48 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 45atsrepj9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Mar 2025 11:45:48 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52EBjiGK60096996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Mar 2025 11:45:44 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 54D0820043; Fri, 14 Mar 2025 11:45:44 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0BE3F20040; Fri, 14 Mar 2025 11:45:41 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.22.126]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 14 Mar 2025 11:45:40 +0000 (GMT) From: Shrikanth Hegde To: maddy@linux.ibm.com, linuxppc-dev@lists.ozlabs.org Cc: sshegde@linux.ibm.com, npiggin@gmail.com, christophe.leroy@csgroup.eu, mpe@ellerman.id.au, peterz@infradead.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, mahesh@linux.ibm.com, oohall@gmail.com, hbathini@linux.ibm.com, dhowells@redhat.com, haren@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] powerpc: sysdev: use lock guard for mutex Date: Fri, 14 Mar 2025 17:15:02 +0530 Message-ID: <20250314114502.2083434-7-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250314114502.2083434-1-sshegde@linux.ibm.com> References: <20250314114502.2083434-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pyT2PcrcHIbI7Sw-c9Fuwi2J3WaI7oLp X-Proofpoint-ORIG-GUID: V3gfsykiNoCverF_y5D3hAhRxSGHxm8T X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-14_04,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 bulkscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=771 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503140091 Content-Type: text/plain; charset="utf-8" use guard(mutex) for scope based resource management of mutex This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u Signed-off-by: Shrikanth Hegde Reviewed-by: Srikar Dronamraju --- arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c b/arch/powerpc/sys= dev/fsl_mpic_timer_wakeup.c index ce6c739c51e5..bbfc7c39b957 100644 --- a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c +++ b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c @@ -75,7 +75,7 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev, if (kstrtoll(buf, 0, &interval)) return -EINVAL; =20 - mutex_lock(&sysfs_lock); + guard(mutex)(&sysfs_lock); =20 if (fsl_wakeup->timer) { disable_irq_wake(fsl_wakeup->timer->irq); @@ -84,14 +84,12 @@ static ssize_t fsl_timer_wakeup_store(struct device *de= v, } =20 if (!interval) { - mutex_unlock(&sysfs_lock); return count; } =20 fsl_wakeup->timer =3D mpic_request_timer(fsl_mpic_timer_irq, fsl_wakeup, interval); if (!fsl_wakeup->timer) { - mutex_unlock(&sysfs_lock); return -EINVAL; } =20 @@ -99,15 +97,11 @@ static ssize_t fsl_timer_wakeup_store(struct device *de= v, if (ret) { mpic_free_timer(fsl_wakeup->timer); fsl_wakeup->timer =3D NULL; - mutex_unlock(&sysfs_lock); - return ret; } =20 mpic_start_timer(fsl_wakeup->timer); =20 - mutex_unlock(&sysfs_lock); - return count; } =20 --=20 2.39.3