From nobody Thu Dec 18 13:40:51 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 EDF173191CD; Mon, 15 Dec 2025 03:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765769379; cv=none; b=SfOK+gff/KmvUKrvz2JYn9shY5vt9a/ki2Ow6fViU3xm8zbzKl4lm6Izgxnz/ltSN6HP0gwSUurzeeI2v4bsTKZPlesKOGZgz8xnklqCfVcLgOpP9qQBs0muIoD7gLS9/xUkwjkhbB1hvu5kE8odksCMF7wcsbz8k1aaGbgYKUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765769379; c=relaxed/simple; bh=r31nD7jiWlPdR4ZXugrEqJDU8tuRSXY+4l7DkPndW2Y=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=kZ4pDeXQTdubKV7p9koFMsThZMqkpAHdfxTZyoBGgNLKKBLDEVXProQP3T7B4Xchb2jDBwiHnSKqhA4wP2zGNxXzYBQU+wvPlXFgUXTdks37yj8OXJVqTg3HlQHWYwRfHKGQB5t0ouu55ZjFfEsSmHT1vAq/bUc1Imyiva9zBn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 431430bed96611f0a38c85956e01ac42-20251215 X-CID-CACHE: Type:Local,Time:202512151127+08,HitQuantity:1 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.6,REQID:0eae8823-bc0c-458e-9707-db6ad194835e,IP:0,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:0 X-CID-META: VersionHash:a9d874c,CLOUDID:a132ce9fff8162bab067a6be75353638,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|850|898,TC:nil,Content:0|15|50,EDM:- 3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,A V:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 431430bed96611f0a38c85956e01ac42-20251215 X-User: jiangyunshui@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1619340947; Mon, 15 Dec 2025 11:29:28 +0800 From: chen zhang To: hdegoede@redhat.com, hansg@kernel.org, ilpo.jarvinen@linux.intel.com, frank@f-seidel.de Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, chenzhang_0901@163.com, chen zhang Subject: [PATCH] platform/x86: Switch to guard(mutex) Date: Mon, 15 Dec 2025 11:29:24 +0800 Message-Id: <20251215032924.50854-1-chenzhang@kylinos.cn> X-Mailer: git-send-email 2.25.1 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 Content-Type: text/plain; charset="utf-8" Instead of using the 'goto label; mutex_unlock()' pattern use 'guard(mutex)' which will release the mutex when it goes out of scope. Signed-off-by: chen zhang --- drivers/platform/x86/hdaps.c | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/platform/x86/hdaps.c b/drivers/platform/x86/hdaps.c index f11f726d2062..2a11bcaa52f2 100644 --- a/drivers/platform/x86/hdaps.c +++ b/drivers/platform/x86/hdaps.c @@ -147,18 +147,16 @@ static int hdaps_readb_one(unsigned int port, u8 *val) { int ret; =20 - mutex_lock(&hdaps_mtx); + guard(mutex)(&hdaps_mtx); =20 /* do a sync refresh -- we need to be sure that we read fresh data */ ret =3D __device_refresh_sync(); if (ret) - goto out; + return ret; =20 *val =3D inb(port); __device_complete(); =20 -out: - mutex_unlock(&hdaps_mtx); return ret; } =20 @@ -208,12 +206,12 @@ static int hdaps_device_init(void) { int total, ret =3D -ENXIO; =20 - mutex_lock(&hdaps_mtx); + guard(mutex)(&hdaps_mtx); =20 outb(0x13, 0x1610); outb(0x01, 0x161f); if (__wait_latch(0x161f, 0x00)) - goto out; + return ret; =20 /* * Most ThinkPads return 0x01. @@ -226,7 +224,7 @@ static int hdaps_device_init(void) if (__check_latch(0x1611, 0x03) && __check_latch(0x1611, 0x02) && __check_latch(0x1611, 0x01)) - goto out; + return ret; =20 printk(KERN_DEBUG "hdaps: initial latch check good (0x%02x)\n", __get_latch(0x1611)); @@ -235,29 +233,29 @@ static int hdaps_device_init(void) outb(0x81, 0x1611); outb(0x01, 0x161f); if (__wait_latch(0x161f, 0x00)) - goto out; + return ret; if (__wait_latch(0x1611, 0x00)) - goto out; + return ret; if (__wait_latch(0x1612, 0x60)) - goto out; + return ret; if (__wait_latch(0x1613, 0x00)) - goto out; + return ret; outb(0x14, 0x1610); outb(0x01, 0x1611); outb(0x01, 0x161f); if (__wait_latch(0x161f, 0x00)) - goto out; + return ret; outb(0x10, 0x1610); outb(0xc8, 0x1611); outb(0x00, 0x1612); outb(0x02, 0x1613); outb(0x01, 0x161f); if (__wait_latch(0x161f, 0x00)) - goto out; + return ret; if (__device_refresh_sync()) - goto out; + return ret; if (__wait_latch(0x1611, 0x00)) - goto out; + return ret; =20 /* we have done our dance, now let's wait for the applause */ for (total =3D INIT_TIMEOUT_MSECS; total > 0; total -=3D INIT_WAIT_MSECS)= { @@ -273,8 +271,6 @@ static int hdaps_device_init(void) msleep(INIT_WAIT_MSECS); } =20 -out: - mutex_unlock(&hdaps_mtx); return ret; } =20 @@ -322,17 +318,14 @@ static void hdaps_mousedev_poll(struct input_dev *inp= ut_dev) { int x, y; =20 - mutex_lock(&hdaps_mtx); + guard(mutex)(&hdaps_mtx); =20 if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y)) - goto out; + return; =20 input_report_abs(input_dev, ABS_X, x - rest_x); input_report_abs(input_dev, ABS_Y, y - rest_y); input_sync(input_dev); - -out: - mutex_unlock(&hdaps_mtx); } =20 =20 --=20 2.25.1