* Re: [PATCH v2 0/2] Input: Remove dev_err_probe() if error is -ENOMEM
From: Dmitry Torokhov @ 2025-10-18 4:44 UTC (permalink / raw)
To: Xichao Zhao
Cc: Heiko Stuebner,
open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
open list
In-Reply-To: <20250822034751.244248-1-zhao.xichao@vivo.com>
On Fri, Aug 22, 2025 at 11:47:47AM +0800, Xichao Zhao wrote:
> The dev_err_probe() doesn't do anything when error is '-ENOMEM'.
> Therefore, remove the useless call to dev_err_probe(), and just
> return the value instead.
Adjusted the subjects and applied the lot, thank you.
Thanks.
--
Dmitry
^ permalink raw reply
* Re: [PATCH v3] dt-bindings: input: Convert MELFAS MIP4 Touchscreen to DT schema
From: Dmitry Torokhov @ 2025-10-18 4:34 UTC (permalink / raw)
To: Ariel D'Alessandro
Cc: angelogioacchino.delregno, conor+dt, krzk+dt, robh, devicetree,
kernel, linux-input, linux-kernel
In-Reply-To: <20251001183809.83472-1-ariel.dalessandro@collabora.com>
On Wed, Oct 01, 2025 at 03:38:09PM -0300, Ariel D'Alessandro wrote:
> Convert the existing text-based DT bindings for MELFAS MIP4 Touchscreen
> controller to a DT schema.
>
> Signed-off-by: Ariel D'Alessandro <ariel.dalessandro@collabora.com>
> Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Applied, thank you.
--
Dmitry
^ permalink raw reply
* Re: [PATCH v2 2/2] dt-bindings: touchscreen: move ar1021.txt to trivial-touch.yaml
From: Dmitry Torokhov @ 2025-10-18 4:22 UTC (permalink / raw)
To: Frank Li
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
open list, imx
In-Reply-To: <20250926184720.391335-2-Frank.Li@nxp.com>
On Fri, Sep 26, 2025 at 02:47:12PM -0400, Frank Li wrote:
> ar1021 have only reg and interrupts property beside touch common
> properties. So move context of ar1021.txt into trivial-touch.yaml.
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
Applied, thank you.
--
Dmitry
^ permalink raw reply
* Re: [PATCH v2 1/2] dt-bindings: touchscreen: rename maxim,max11801.yaml to trivial-touch.yaml
From: Dmitry Torokhov @ 2025-10-18 4:22 UTC (permalink / raw)
To: Frank Li
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
open list, imx
In-Reply-To: <20250926184720.391335-1-Frank.Li@nxp.com>
On Fri, Sep 26, 2025 at 02:47:11PM -0400, Frank Li wrote:
> Rename maxim,max11801.yaml to trivial-touch.yaml for simple i2c touch
> controller with one interrupt and common touch properties.
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
Applied, thank you.
--
Dmitry
^ permalink raw reply
* Re: [PATCH] Input: pegasus-notetaker - fix out-of-bounds access vulnerability in pegasus_parse_packet() function of the pegasus driver
From: Dmitry Torokhov @ 2025-10-18 1:08 UTC (permalink / raw)
To: pip-izony; +Cc: Kyungtae Kim, linux-input, linux-kernel, stable
In-Reply-To: <20251007214131.3737115-2-eeodqql09@gmail.com>
Hi,
On Tue, Oct 07, 2025 at 05:41:32PM -0400, pip-izony wrote:
> From: Seungjin Bae <eeodqql09@gmail.com>
>
> In the pegasus_notetaker driver, the pegasus_probe() function allocates
> the URB transfer buffer using the wMaxPacketSize value from
> the endpoint descriptor. An attacker can use a malicious USB descriptor
> to force the allocation of a very small buffer.
>
> Subsequently, if the device sends an interrupt packet with a specific
> pattern (e.g., where the first byte is 0x80 or 0x42),
> the pegasus_parse_packet() function parses the packet without checking
> the allocated buffer size. This leads to an out-of-bounds memory access,
> which could result in a system panic.
>
> Fixes: 948bf18 ("Input: remove third argument of usb_maxpacket()")
> Signed-off-by: Seungjin Bae <eeodqql09@gmail.com>
> ---
> drivers/input/tablet/pegasus_notetaker.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/input/tablet/pegasus_notetaker.c b/drivers/input/tablet/pegasus_notetaker.c
> index 8d6b71d59793..6c4199712a4e 100644
> --- a/drivers/input/tablet/pegasus_notetaker.c
> +++ b/drivers/input/tablet/pegasus_notetaker.c
> @@ -311,6 +311,11 @@ static int pegasus_probe(struct usb_interface *intf,
> }
>
> pegasus->data_len = usb_maxpacket(dev, pipe);
> + if (pegasus->data_len < 5) {
The packet size is actually 6 (status + color + 2-byte X coordinate +
2-byte Y coordinate) so there's still off-by-one error.
I fixed it up and applied.
Thanks.
--
Dmitry
^ permalink raw reply
* Re: [PATCH v2 00/27 5.10.y] Backport minmax.h updates from v6.17-rc7
From: Nathan Chancellor @ 2025-10-17 16:09 UTC (permalink / raw)
To: Greg KH
Cc: Eliav Farber, stable, linux, jdike, richard, anton.ivanov,
dave.hansen, luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck,
qiuxu.zhuo, mchehab, james.morse, rric, harry.wentland,
sunpeng.li, alexander.deucher, christian.koenig, airlied, daniel,
evan.quan, james.qian.wang, liviu.dudau, mihail.atanassov,
brian.starkey, maarten.lankhorst, mripard, tzimmermann, robdclark,
sean, jdelvare, linux, fery, dmitry.torokhov, agk, snitzer,
dm-devel, rajur, davem, kuba, peppe.cavallaro, alexandre.torgue,
joabreu, mcoquelin.stm32, malattia, hdegoede, mgross,
intel-linux-scu, artur.paszkiewicz, jejb, martin.petersen,
sakari.ailus, clm, josef, dsterba, xiang, chao, jack, tytso,
adilger.kernel, dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, sashal, ruanjinjie, David.Laight, herve.codina, Jason,
keescook, kbusch, bvanassche, ndesaulniers, linux-arm-kernel,
linux-kernel, linux-um, linux-edac, amd-gfx, dri-devel,
linux-arm-msm, freedreno, linux-hwmon, linux-input, linux-media,
netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
In-Reply-To: <2025101704-rumble-chatroom-60b5@gregkh>
On Fri, Oct 17, 2025 at 05:03:02PM +0200, Greg KH wrote:
> On Fri, Oct 17, 2025 at 09:04:52AM +0000, Eliav Farber wrote:
> > This series backports 27 patches to update minmax.h in the 5.10.y
> > branch, aligning it with v6.17-rc7.
> >
> > The ultimate goal is to synchronize all long-term branches so that they
> > include the full set of minmax.h changes.
> >
> > - 6.12.y has already been backported; the changes are included in
> > v6.12.49.
> > - 6.6.y has already been backported; the changes are included in
> > v6.6.109.
> > - 6.1.y has already been backported; the changes are currently in the
> > 6.1-stable tree.
> > - 5.15.y has already been backported; the changes are currently in the
> > 5.15-stable tree.
>
> With this series applied, on an arm64 server, building 'allmodconfig', I
> get the following build error.
>
> Oddly I don't see it on my x86 server, perhaps due to different compiler
> versions?
>
> Any ideas?
>
> thanks,
>
> greg k-h
>
> ------------------------
>
> In function ‘rt2800_txpower_to_dev’,
> inlined from ‘rt2800_config_channel’ at ../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:4022:25:
> ./../include/linux/compiler_types.h:309:45: error: call to ‘__compiletime_assert_1168’ declared with attribute error: clamp() low limit -7 greater than high limit 15
> 309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> | ^
> ./../include/linux/compiler_types.h:290:25: note: in definition of macro ‘__compiletime_assert’
> 290 | prefix ## suffix(); \
> | ^~~~~~
> ./../include/linux/compiler_types.h:309:9: note: in expansion of macro ‘_compiletime_assert’
> 309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> | ^~~~~~~~~~~~~~~~~~~
> ../include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
> 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> | ^~~~~~~~~~~~~~~~~~
> ../include/linux/minmax.h:188:9: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
> 188 | BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
> | ^~~~~~~~~~~~~~~~
> ../include/linux/minmax.h:195:9: note: in expansion of macro ‘__clamp_once’
> 195 | __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
> | ^~~~~~~~~~~~
> ../include/linux/minmax.h:218:36: note: in expansion of macro ‘__careful_clamp’
> 218 | #define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi)
> | ^~~~~~~~~~~~~~~
> ../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:3980:24: note: in expansion of macro ‘clamp_t’
> 3980 | return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
> | ^~~~~~~
Missing commit 3bc753c06dd0 ("kbuild: treat char as always unsigned")?
Cheers,
Nathan
^ permalink raw reply
* Re: [PATCH v2 00/27 5.10.y] Backport minmax.h updates from v6.17-rc7
From: Greg KH @ 2025-10-17 15:03 UTC (permalink / raw)
To: Eliav Farber
Cc: stable, linux, jdike, richard, anton.ivanov, dave.hansen, luto,
peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, mchehab,
james.morse, rric, harry.wentland, sunpeng.li, alexander.deucher,
christian.koenig, airlied, daniel, evan.quan, james.qian.wang,
liviu.dudau, mihail.atanassov, brian.starkey, maarten.lankhorst,
mripard, tzimmermann, robdclark, sean, jdelvare, linux, fery,
dmitry.torokhov, agk, snitzer, dm-devel, rajur, davem, kuba,
peppe.cavallaro, alexandre.torgue, joabreu, mcoquelin.stm32,
malattia, hdegoede, mgross, intel-linux-scu, artur.paszkiewicz,
jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, xiang,
chao, jack, tytso, adilger.kernel, dushistov, luc.vanoostenryck,
rostedt, pmladek, sergey.senozhatsky, andriy.shevchenko, linux,
minchan, ngupta, akpm, kuznet, yoshfuji, pablo, kadlec, fw,
jmaloy, ying.xue, willy, sashal, ruanjinjie, David.Laight,
herve.codina, Jason, keescook, kbusch, nathan, bvanassche,
ndesaulniers, linux-arm-kernel, linux-kernel, linux-um,
linux-edac, amd-gfx, dri-devel, linux-arm-msm, freedreno,
linux-hwmon, linux-input, linux-media, netdev, linux-stm32,
platform-driver-x86, linux-scsi, linux-staging, linux-btrfs,
linux-erofs, linux-ext4, linux-sparse, linux-mm, netfilter-devel,
coreteam, tipc-discussion
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
On Fri, Oct 17, 2025 at 09:04:52AM +0000, Eliav Farber wrote:
> This series backports 27 patches to update minmax.h in the 5.10.y
> branch, aligning it with v6.17-rc7.
>
> The ultimate goal is to synchronize all long-term branches so that they
> include the full set of minmax.h changes.
>
> - 6.12.y has already been backported; the changes are included in
> v6.12.49.
> - 6.6.y has already been backported; the changes are included in
> v6.6.109.
> - 6.1.y has already been backported; the changes are currently in the
> 6.1-stable tree.
> - 5.15.y has already been backported; the changes are currently in the
> 5.15-stable tree.
With this series applied, on an arm64 server, building 'allmodconfig', I
get the following build error.
Oddly I don't see it on my x86 server, perhaps due to different compiler
versions?
Any ideas?
thanks,
greg k-h
------------------------
In function ‘rt2800_txpower_to_dev’,
inlined from ‘rt2800_config_channel’ at ../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:4022:25:
./../include/linux/compiler_types.h:309:45: error: call to ‘__compiletime_assert_1168’ declared with attribute error: clamp() low limit -7 greater than high limit 15
309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
./../include/linux/compiler_types.h:290:25: note: in definition of macro ‘__compiletime_assert’
290 | prefix ## suffix(); \
| ^~~~~~
./../include/linux/compiler_types.h:309:9: note: in expansion of macro ‘_compiletime_assert’
309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
../include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
../include/linux/minmax.h:188:9: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
188 | BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
| ^~~~~~~~~~~~~~~~
../include/linux/minmax.h:195:9: note: in expansion of macro ‘__clamp_once’
195 | __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
| ^~~~~~~~~~~~
../include/linux/minmax.h:218:36: note: in expansion of macro ‘__careful_clamp’
218 | #define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi)
| ^~~~~~~~~~~~~~~
../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:3980:24: note: in expansion of macro ‘clamp_t’
3980 | return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
| ^~~~~~~
In function ‘rt2800_txpower_to_dev’,
inlined from ‘rt2800_config_channel’ at ../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:4024:25:
./../include/linux/compiler_types.h:309:45: error: call to ‘__compiletime_assert_1168’ declared with attribute error: clamp() low limit -7 greater than high limit 15
309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
./../include/linux/compiler_types.h:290:25: note: in definition of macro ‘__compiletime_assert’
290 | prefix ## suffix(); \
| ^~~~~~
./../include/linux/compiler_types.h:309:9: note: in expansion of macro ‘_compiletime_assert’
309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
../include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
../include/linux/minmax.h:188:9: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
188 | BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
| ^~~~~~~~~~~~~~~~
../include/linux/minmax.h:195:9: note: in expansion of macro ‘__clamp_once’
195 | __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
| ^~~~~~~~~~~~
../include/linux/minmax.h:218:36: note: in expansion of macro ‘__careful_clamp’
218 | #define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi)
| ^~~~~~~~~~~~~~~
../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:3980:24: note: in expansion of macro ‘clamp_t’
3980 | return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
| ^~~~~~~
In function ‘rt2800_txpower_to_dev’,
inlined from ‘rt2800_config_channel’ at ../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:4028:4:
./../include/linux/compiler_types.h:309:45: error: call to ‘__compiletime_assert_1168’ declared with attribute error: clamp() low limit -7 greater than high limit 15
309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
./../include/linux/compiler_types.h:290:25: note: in definition of macro ‘__compiletime_assert’
290 | prefix ## suffix(); \
| ^~~~~~
./../include/linux/compiler_types.h:309:9: note: in expansion of macro ‘_compiletime_assert’
309 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
../include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
../include/linux/minmax.h:188:9: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
188 | BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
| ^~~~~~~~~~~~~~~~
../include/linux/minmax.h:195:9: note: in expansion of macro ‘__clamp_once’
195 | __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
| ^~~~~~~~~~~~
../include/linux/minmax.h:218:36: note: in expansion of macro ‘__careful_clamp’
218 | #define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi)
| ^~~~~~~~~~~~~~~
../drivers/net/wireless/ralink/rt2x00/rt2800lib.c:3980:24: note: in expansion of macro ‘clamp_t’
3980 | return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
| ^~~~~~~
make[6]: *** [../scripts/Makefile.build:286: drivers/net/wireless/ralink/rt2x00/rt2800lib.o] Error 1
make[5]: *** [../scripts/Makefile.build:503: drivers/net/wireless/ralink/rt2x00] Error 2
make[4]: *** [../scripts/Makefile.build:503: drivers/net/wireless/ralink] Error 2
make[4]: *** Waiting for unfinished jobs....
^ permalink raw reply
* Re: 答复: [External Mail]Re: [PATCH v2] HID: hid-input: only ignore 0 battery events for digitizers
From: Jiri Kosina @ 2025-10-17 15:51 UTC (permalink / raw)
To: 卢国宏
Cc: Dmitry Torokhov, Benjamin Tissoires, kenalba@google.com,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
李鹏
In-Reply-To: <c717d9d1483f4436a9ba6e4266ea4e55@xiaomi.com>
On Fri, 17 Oct 2025, 卢国宏 wrote:
> Where can I find information about your commits? Is it
> "https://web.git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git/log/?h=for-6.17/upstream-fixes"?
> So far, I haven't seen any information about this commit. I'll need this
> information when I submit this code to Google's GKI. Thank you!
The queue of fixes for 6.18 is at
https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git/log/?h=for-6.18/upstream-fixes
and it's just now on its way to Linus' tree:
https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git/log/?h=for-linus
--
Jiri Kosina
SUSE Labs
^ permalink raw reply
* Re: [PATCH v2 0/6] HID: intel-ish-hid: Various power management improvements for hibernation
From: Jiri Kosina @ 2025-10-17 15:48 UTC (permalink / raw)
To: Zhang Lixu; +Cc: linux-input, srinivas.pandruvada, benjamin.tissoires
In-Reply-To: <20251017022218.1292451-1-lixu.zhang@intel.com>
On Fri, 17 Oct 2025, Zhang Lixu wrote:
> - Separating hibernate callbacks in dev_pm_ops for clearer power state transitions
> - Using IPC RESET in ish_wakeup() to ensure reliable device wakeup
> - Scheduling firmware reset work on RESET_NOTIFY/ACK for robust recovery
> - Resetting client state on resume from D3 to maintain consistency
> - Enhancing resume logic in ishtp-hid-client for better stability
>
> These patches enhance reliability, improve power management flow. All changes
> have been validated on TwinLake (ISH 5.4), ArrowLake (ISH 5.6), and PantherLake
> (ISH 5.8) platforms.
>
> v2:
> - Rebased on top of [PATCH] HID: intel-ish-hid: Use dedicated unbound workqueues to prevent resume blocking
> - Changes in [PATCH v2 5/6] HID: intel-ish-hid: Use IPC RESET instead of void message in ish_wakeup()
> * Set the HW ready timeout to 10 seconds, matching the original timeout
> value used in ish_wakeup(), to prevent timeout issues on devices like
> the Lenovo ThinkPad X1 Titanium Gen 1 that require approximately 4
> seconds to become ready after wakeup.
> * Added RECVD_HW_READY_TIMEOUT macro for better code maintainability.
Applied to hid.git#for-6.19/intel-ish-v2, thanks.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply
* Re: [PATCH] HID: intel-ish-hid: Use dedicated unbound workqueues to prevent resume blocking
From: Jiri Kosina @ 2025-10-17 15:47 UTC (permalink / raw)
To: Zhang Lixu
Cc: linux-input, srinivas.pandruvada, benjamin.tissoires, selina.wang
In-Reply-To: <20251010055254.532925-1-lixu.zhang@intel.com>
On Fri, 10 Oct 2025, Zhang Lixu wrote:
> During suspend/resume tests with S2IDLE, some ISH functional failures were
> observed because of delay in executing ISH resume handler. Here
> schedule_work() is used from resume handler to do actual work.
> schedule_work() uses system_wq, which is a per CPU work queue. Although
> the queuing is not bound to a CPU, but it prefers local CPU of the caller,
> unless prohibited.
>
> Users of this work queue are not supposed to queue long running work.
> But in practice, there are scenarios where long running work items are
> queued on other unbound workqueues, occupying the CPU. As a result, the
> ISH resume handler may not get a chance to execute in a timely manner.
>
> In one scenario, one of the ish_resume_handler() executions was delayed
> nearly 1 second because another work item on an unbound workqueue occupied
> the same CPU. This delay causes ISH functionality failures.
>
> A similar issue was previously observed where the ISH HID driver timed out
> while getting the HID descriptor during S4 resume in the recovery kernel,
> likely caused by the same workqueue contention problem.
>
> Create dedicated unbound workqueues for all ISH operations to allow work
> items to execute on any available CPU, eliminating CPU-specific bottlenecks
> and improving resume reliability under varying system loads. Also ISH has
> three different components, a bus driver which implements ISH protocols, a
> PCI interface layer and HID interface. Use one dedicated work queue for all
> of them.
>
> Signed-off-by: Zhang Lixu <lixu.zhang@intel.com>
Applied to hid.git#for-6.19/intel-ish-v2, thanks.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply
* Re: [PATCH v2 01/27 5.10.y] overflow, tracing: Define the is_signed_type() macro once
From: Greg KH @ 2025-10-17 13:21 UTC (permalink / raw)
To: Farber, Eliav
Cc: stable@vger.kernel.org, linux@armlinux.org.uk, jdike@addtoit.com,
richard@nod.at, anton.ivanov@cambridgegreys.com,
dave.hansen@linux.intel.com, luto@kernel.org,
peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, x86@kernel.org, hpa@zytor.com, tony.luck@intel.com,
qiuxu.zhuo@intel.com, mchehab@kernel.org, james.morse@arm.com,
rric@kernel.org, harry.wentland@amd.com, sunpeng.li@amd.com,
alexander.deucher@amd.com, christian.koenig@amd.com,
airlied@linux.ie, daniel@ffwll.ch, evan.quan@amd.com,
james.qian.wang@arm.com, liviu.dudau@arm.com,
mihail.atanassov@arm.com, brian.starkey@arm.com,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, robdclark@gmail.com, sean@poorly.run,
jdelvare@suse.com, linux@roeck-us.net, fery@cypress.com,
dmitry.torokhov@gmail.com, agk@redhat.com, snitzer@redhat.com,
dm-devel@redhat.com, rajur@chelsio.com, davem@davemloft.net,
kuba@kernel.org, peppe.cavallaro@st.com, alexandre.torgue@st.com,
joabreu@synopsys.com, mcoquelin.stm32@gmail.com,
malattia@linux.it, hdegoede@redhat.com, mgross@linux.intel.com,
intel-linux-scu@intel.com, artur.paszkiewicz@intel.com,
jejb@linux.ibm.com, martin.petersen@oracle.com,
sakari.ailus@linux.intel.com, clm@fb.com, josef@toxicpanda.com,
dsterba@suse.com, xiang@kernel.org, chao@kernel.org,
jack@suse.com, tytso@mit.edu, adilger.kernel@dilger.ca,
dushistov@mail.ru, luc.vanoostenryck@gmail.com,
rostedt@goodmis.org, pmladek@suse.com,
sergey.senozhatsky@gmail.com, andriy.shevchenko@linux.intel.com,
linux@rasmusvillemoes.dk, minchan@kernel.org, ngupta@vflare.org,
akpm@linux-foundation.org, kuznet@ms2.inr.ac.ru,
yoshfuji@linux-ipv6.org, pablo@netfilter.org,
kadlec@netfilter.org, fw@strlen.de, jmaloy@redhat.com,
ying.xue@windriver.com, willy@infradead.org, sashal@kernel.org,
ruanjinjie@huawei.com, David.Laight@aculab.com,
herve.codina@bootlin.com, Jason@zx2c4.com, keescook@chromium.org,
kbusch@kernel.org, nathan@kernel.org, bvanassche@acm.org,
ndesaulniers@google.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-um@lists.infradead.org,
linux-edac@vger.kernel.org, amd-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
freedreno@lists.freedesktop.org, linux-hwmon@vger.kernel.org,
linux-input@vger.kernel.org, linux-media@vger.kernel.org,
netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
platform-driver-x86@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-staging@lists.linux.dev, linux-btrfs@vger.kernel.org,
linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org,
linux-sparse@vger.kernel.org, linux-mm@kvack.org,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
tipc-discussion@lists.sourceforge.net, Arnd Bergmann,
Dan Williams, Eric Dumazet, Isabella Basso, Josh Poimboeuf,
Masami Hiramatsu, Sander Vanheule, Vlastimil Babka, Yury Norov
In-Reply-To: <CH0PR18MB54337BD648C23CBE40C1060CC6F6A@CH0PR18MB5433.namprd18.prod.outlook.com>
On Fri, Oct 17, 2025 at 12:16:27PM +0000, Farber, Eliav wrote:
> > On Fri, Oct 17, 2025 at 09:04:53AM +0000, Eliav Farber wrote:
> > > From: Bart Van Assche <bvanassche@acm.org>
> > >
> > > [ Upstream commit 92d23c6e94157739b997cacce151586a0d07bb8a ]
> >
> > This isn't in 5.15.y, why is it needed in 5.10.y?
>
> This is the mainline commit:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/overflow.h?h=v6.18-rc1&id=92d23c6e94157739b997cacce151586a0d07bb8a
>
> The commit hash is 92d23c6e94157739b997cacce151586a0d07bb8a, which is
> the one I used for the backport.
>
> And here is the corresponding commit in the 5.15.y branch:
> https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/include/linux/overflow.h?h=v5.15.194&id=ed6e37e30826b12572636c6bbfe6319233690c90
> However, the commit message there references a different hash:
> a49a64b5bf195381c09202c524f0f84b5f3e816f.
Ugh, that hash is invalid, I missed that :(
Thanks for the info, I'll go work on queueing these up.
greg k-h
^ permalink raw reply
* *** Urgent Change ***
From: Vlad Dinu @ 2025-10-17 12:45 UTC (permalink / raw)
To: linux-input
Hello,
I am Vlad Dinu, the newly appointed Director of IMF Legal
Affairs, Security and Investigation. I have been given the
responsibility to look into all the payments that are still
pending and owed to fund beneficiaries / scam victims worldwide.
This action was taken because there have been issues with some
banks not being able to send or release money to the correct
beneficiary accounts. We have found out that some directors in
different organizations are moving pending funds to their own
chosen accounts instead of where they should go.
During my investigation, I discovered that an account was
reported to redirect your funds to a bank in Sweden.
The details of that account are provided below. I would like you
to confirm if you are aware of this new information, as we are
now planning to send the payment to the account mentioned.
NAME OF BENEFICIARY: ERIK KASPERSSON
BANK NAME: SWEDBANK AB
ADDRESS: REPSLAGAREGATAN 23A, 582 22 LINKÖPING, SWEDEN
SWIFT CODE: SWEDSESS
ACCOUNT NUMBER: 84806-31282205
A payment instruction has been issued by the Department of
Treasury for an immediate release of your payment to the bank
account above without further prejudice. We cannot approve or
schedule payment to the
given bank account without your confirmation. May we proceed with
the transfer to the Beneficiary: Erik Kaspersson, bank account in
Sweden?
I await your urgent response.
Mr. Vlad Dinu.
^ permalink raw reply
* RE: [PATCH v2 01/27 5.10.y] overflow, tracing: Define the is_signed_type() macro once
From: Farber, Eliav @ 2025-10-17 12:16 UTC (permalink / raw)
To: Greg KH
Cc: stable@vger.kernel.org, linux@armlinux.org.uk, jdike@addtoit.com,
richard@nod.at, anton.ivanov@cambridgegreys.com,
dave.hansen@linux.intel.com, luto@kernel.org,
peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, x86@kernel.org, hpa@zytor.com, tony.luck@intel.com,
qiuxu.zhuo@intel.com, mchehab@kernel.org, james.morse@arm.com,
rric@kernel.org, harry.wentland@amd.com, sunpeng.li@amd.com,
alexander.deucher@amd.com, christian.koenig@amd.com,
airlied@linux.ie, daniel@ffwll.ch, evan.quan@amd.com,
james.qian.wang@arm.com, liviu.dudau@arm.com,
mihail.atanassov@arm.com, brian.starkey@arm.com,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, robdclark@gmail.com, sean@poorly.run,
jdelvare@suse.com, linux@roeck-us.net, fery@cypress.com,
dmitry.torokhov@gmail.com, agk@redhat.com, snitzer@redhat.com,
dm-devel@redhat.com, rajur@chelsio.com, davem@davemloft.net,
kuba@kernel.org, peppe.cavallaro@st.com, alexandre.torgue@st.com,
joabreu@synopsys.com, mcoquelin.stm32@gmail.com,
malattia@linux.it, hdegoede@redhat.com, mgross@linux.intel.com,
intel-linux-scu@intel.com, artur.paszkiewicz@intel.com,
jejb@linux.ibm.com, martin.petersen@oracle.com,
sakari.ailus@linux.intel.com, clm@fb.com, josef@toxicpanda.com,
dsterba@suse.com, xiang@kernel.org, chao@kernel.org,
jack@suse.com, tytso@mit.edu, adilger.kernel@dilger.ca,
dushistov@mail.ru, luc.vanoostenryck@gmail.com,
rostedt@goodmis.org, pmladek@suse.com,
sergey.senozhatsky@gmail.com, andriy.shevchenko@linux.intel.com,
linux@rasmusvillemoes.dk, minchan@kernel.org, ngupta@vflare.org,
akpm@linux-foundation.org, kuznet@ms2.inr.ac.ru,
yoshfuji@linux-ipv6.org, pablo@netfilter.org,
kadlec@netfilter.org, fw@strlen.de, jmaloy@redhat.com,
ying.xue@windriver.com, willy@infradead.org, sashal@kernel.org,
ruanjinjie@huawei.com, David.Laight@aculab.com,
herve.codina@bootlin.com, Jason@zx2c4.com, keescook@chromium.org,
kbusch@kernel.org, nathan@kernel.org, bvanassche@acm.org,
ndesaulniers@google.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-um@lists.infradead.org,
linux-edac@vger.kernel.org, amd-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
freedreno@lists.freedesktop.org, linux-hwmon@vger.kernel.org,
linux-input@vger.kernel.org, linux-media@vger.kernel.org,
netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
platform-driver-x86@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-staging@lists.linux.dev, linux-btrfs@vger.kernel.org,
linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org,
linux-sparse@vger.kernel.org, linux-mm@kvack.org,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
tipc-discussion@lists.sourceforge.net, Arnd Bergmann,
Dan Williams, Eric Dumazet, Isabella Basso, Josh Poimboeuf,
Masami Hiramatsu, Sander Vanheule, Vlastimil Babka, Yury Norov
In-Reply-To: <2025101708-obtuse-ellipse-e355@gregkh>
> On Fri, Oct 17, 2025 at 09:04:53AM +0000, Eliav Farber wrote:
> > From: Bart Van Assche <bvanassche@acm.org>
> >
> > [ Upstream commit 92d23c6e94157739b997cacce151586a0d07bb8a ]
>
> This isn't in 5.15.y, why is it needed in 5.10.y?
This is the mainline commit:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/overflow.h?h=v6.18-rc1&id=92d23c6e94157739b997cacce151586a0d07bb8a
The commit hash is 92d23c6e94157739b997cacce151586a0d07bb8a, which is
the one I used for the backport.
And here is the corresponding commit in the 5.15.y branch:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/include/linux/overflow.h?h=v5.15.194&id=ed6e37e30826b12572636c6bbfe6319233690c90
However, the commit message there references a different hash:
a49a64b5bf195381c09202c524f0f84b5f3e816f.
---
Regards, Eliav
^ permalink raw reply
* Re: [PATCH v2 01/27 5.10.y] overflow, tracing: Define the is_signed_type() macro once
From: Greg KH @ 2025-10-17 11:59 UTC (permalink / raw)
To: Eliav Farber
Cc: stable, linux, jdike, richard, anton.ivanov, dave.hansen, luto,
peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, mchehab,
james.morse, rric, harry.wentland, sunpeng.li, alexander.deucher,
christian.koenig, airlied, daniel, evan.quan, james.qian.wang,
liviu.dudau, mihail.atanassov, brian.starkey, maarten.lankhorst,
mripard, tzimmermann, robdclark, sean, jdelvare, linux, fery,
dmitry.torokhov, agk, snitzer, dm-devel, rajur, davem, kuba,
peppe.cavallaro, alexandre.torgue, joabreu, mcoquelin.stm32,
malattia, hdegoede, mgross, intel-linux-scu, artur.paszkiewicz,
jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, xiang,
chao, jack, tytso, adilger.kernel, dushistov, luc.vanoostenryck,
rostedt, pmladek, sergey.senozhatsky, andriy.shevchenko, linux,
minchan, ngupta, akpm, kuznet, yoshfuji, pablo, kadlec, fw,
jmaloy, ying.xue, willy, sashal, ruanjinjie, David.Laight,
herve.codina, Jason, keescook, kbusch, nathan, bvanassche,
ndesaulniers, linux-arm-kernel, linux-kernel, linux-um,
linux-edac, amd-gfx, dri-devel, linux-arm-msm, freedreno,
linux-hwmon, linux-input, linux-media, netdev, linux-stm32,
platform-driver-x86, linux-scsi, linux-staging, linux-btrfs,
linux-erofs, linux-ext4, linux-sparse, linux-mm, netfilter-devel,
coreteam, tipc-discussion, Arnd Bergmann, Dan Williams,
Eric Dumazet, Isabella Basso, Josh Poimboeuf, Masami Hiramatsu,
Sander Vanheule, Vlastimil Babka, Yury Norov
In-Reply-To: <20251017090519.46992-2-farbere@amazon.com>
On Fri, Oct 17, 2025 at 09:04:53AM +0000, Eliav Farber wrote:
> From: Bart Van Assche <bvanassche@acm.org>
>
> [ Upstream commit 92d23c6e94157739b997cacce151586a0d07bb8a ]
This isn't in 5.15.y, why is it needed in 5.10.y?
thanks,
greg k-h
^ permalink raw reply
* Re: [PATCH v6 0/7] HID: asus: Fix ASUS ROG Laptop's Keyboard backlight handling
From: Antheas Kapenekakis @ 2025-10-17 11:21 UTC (permalink / raw)
To: Denis Benato
Cc: Ilpo Järvinen, platform-driver-x86, linux-input, LKML,
Jiri Kosina, Benjamin Tissoires, Corentin Chary, Luke D . Jones,
Hans de Goede
In-Reply-To: <b74b6d4a-7c9a-47a9-bf65-73bcae525bc0@gmail.com>
On Fri, 17 Oct 2025 at 13:00, Denis Benato <benato.denis96@gmail.com> wrote:
>
>
> On 10/17/25 09:54, Antheas Kapenekakis wrote:
> > On Thu, 16 Oct 2025 at 18:16, Antheas Kapenekakis <lkml@antheas.dev> wrote:
> >> On Thu, 16 Oct 2025 at 17:09, Ilpo Järvinen
> >> <ilpo.jarvinen@linux.intel.com> wrote:
> >>> On Thu, 16 Oct 2025, Antheas Kapenekakis wrote:
> >>>> On Thu, 16 Oct 2025 at 13:57, Denis Benato <benato.denis96@gmail.com> wrote:
> >>>>> On 10/13/25 22:15, Antheas Kapenekakis wrote:
> >>>>>> This is a two part series which does the following:
> >>>>>> - Clean-up init sequence
> >>>>>> - Unify backlight handling to happen under asus-wmi so that all Aura
> >>>>>> devices have synced brightness controls and the backlight button works
> >>>>>> properly when it is on a USB laptop keyboard instead of one w/ WMI.
> >>>>>>
> >>>>>> For more context, see cover letter of V1. Since V5, I removed some patches
> >>>>>> to make this easier to merge.
> >>>>>>
> >>>>>> All comments with these patches had been addressed since V4.
> >>>>> I have loaded this patchset for users of asus-linux project to try out.
> >>>>>
> >>>>> One of them opened a bug report about a kernel bug that happens
> >>>>> consistently when closing the lid of his laptop [1].
> >>>>>
> >>>>> He also sent another piece of kernel log, but didn't specify anything more
> >>>>> about this [2].
> >>>>>
> >>>>> [1] https://pastebin.com/akZx1w10
> >>>>> [2] https://pastebin.com/sKdczPgf
> >>>> Can you provide a link to the bug report? [2] seems unrelated.
> >>>>
> >>>> As for [1], it looks like a trace that stems from a sysfs write to
> >>>> brightness stemming from userspace that follows the same chain it
> >>>> would on a stock kernel and times out. Is it present on a stock
> >>>> kernel?
> >>>>
> >>>> Ilpo should know more about this, could the spinlock be interfering?
> >>> [1] certainly seems to do schedule() from do_kbd_led_set() so it's not
> >>> possible to use spinlock there.
> >>>
> >>> So we're back to what requires the spinlock? And what the spinlock
> >>> protects?
> >> For that invocation, since it is coming from the cdev device owned by
> >> asus_wmi, it protects asus_ref.listeners under do_kbd_led_set.
> >> asus_wmi is protected by the fact it is owned by that device. Spinlock
> >> is not required in this invocation due to not being an IRQ.
> >>
> >> Under asus_hid_event (second to last patch), which is called from an
> >> IRQ, a spinlock is required for protecting both listeners and the
> >> asus_ref.asus, and I suspect that scheduling from an IRQ is not
> >> allowed either. Is that correct?
> > So it is a bit tricky here. When the IRQ fires, it needs to know
> > whether asus-wmi will handle the keyboard brightness event so that it
> > falls back to emitting it.
> >
> > If we want it to know for sure, it needs to access asus_wmi, so it
> > needs a spinlock or an IRQ friendly lock. This way, currently,
> > asus_hid_event will return -EBUSY if there is no led device so the
> > event propagates through hid.
> >
> > If we say that it is good enough to know that it was compiled with
> > IS_REACHABLE(CONFIG_ASUS_WMI), ie the actual implementation of
> > asus_hid_event in asus-wmi will never return an error, then,
> > asus_hid_event can schedule a task to fire the event without a lock,
> > and that task can use a normal locking primitive.
> >
> > If the task needs to be assigned to a device or have a handle,
> > asus_hid_listener can be provided to asus_hid_event, so that it is
> > owned by the calling device.
> >
> > What would the appropriate locking primitive be in this case?
> The right place to look into appears to be Documentation/kernel-hacking/locking.rst
>
> I see mutex being used in various irq handlers, even bmi323-imu but that page has
> many alternatives for irq.
>
> There is rwlock_t but it appears to be using spinlock on certain configurations.
>
> Absolute worst-case scenario you might resort implementing an rwlock with mutexes only.
>
> I would avoid taking decisions based solely on the configuration because ASUS
> makes keyboards and reuses designs across various products, so it is very likely
> at least one model of those keyboards can be confused with a laptop one.
>
> Beside I am sure there must be at the very least one appropriate synchronization primitive,
> so I would discard the configure option.
The bug is not due to the spinlock. Its due to accessing WMI through
an IRQ. A work queue should be used. Using a spinlock is a result of
that omission.
asus-wmi already has workqueues for the other leds but not for the
keyboard one so we can add one.
If we want the IRQ that handles brightness events through
asus_hid_event to know whether a brightness handler is registered
before choosing whether to forward the event, then we will need to use
a spinlock. Since the spinlock protects objects that are setup during
asus-wmi init and removal, this spinlock needs to be in asus-wmi since
hid-asus has a child relationship.
Now, if we assume that hid-asus should be able to handle cases where
asus-wmi is not loaded with proper brightness control and in parallel
support cases where asus-wmi is loaded in a unified manner, then
that's a different class of problem because a device needs to own the
led handler and currently that would be the platform device.
> >> Antheas
> >>> Not related to this particular email in this thread, if the users are
> >>> testing something with different kernels, it's also important to make sure
> >>> that the lockdep configs are enabled in both. As it could be that in one
> >>> kernel lockdep is not enabled and thus it won't do the splat.
> >>>
> >>> --
> >>> i.
> >>>
> >>>
> >>>> My testing on devices that have WMI led controls is a bit limited
> >>>> unfortunately. However, most of our asus users have been happy with
> >>>> this series for around half a year now.
> >>>>
> >>>>>> ---
> >>>>>> V5: https://lore.kernel.org/all/20250325184601.10990-1-lkml@antheas.dev/
> >>>>>> V4: https://lore.kernel.org/lkml/20250324210151.6042-1-lkml@antheas.dev/
> >>>>>> V3: https://lore.kernel.org/lkml/20250322102804.418000-1-lkml@antheas.dev/
> >>>>>> V2: https://lore.kernel.org/all/20250320220924.5023-1-lkml@antheas.dev/
> >>>>>> V1: https://lore.kernel.org/all/20250319191320.10092-1-lkml@antheas.dev/
> >>>>>>
> >>>>>> Changes since V5:
> >>>>>> - It's been a long time
> >>>>>> - Remove addition of RGB as that had some comments I need to work on
> >>>>>> - Remove folio patch (already merged)
> >>>>>> - Remove legacy fix patch 11 from V4. There is a small chance that
> >>>>>> without this patch, some old NKEY keyboards might not respond to
> >>>>>> RGB commands according to Luke, but the kernel driver does not do
> >>>>>> RGB currently. The 0x5d init is done by Armoury crate software in
> >>>>>> Windows. If an issue is found, we can re-add it or just remove patches
> >>>>>> 1/2 before merging. However, init could use the cleanup.
> >>>>>>
> >>>>>> Changes since V4:
> >>>>>> - Fix KConfig (reported by kernel robot)
> >>>>>> - Fix Ilpo's nits, if I missed anything lmk
> >>>>>>
> >>>>>> Changes since V3:
> >>>>>> - Add initializer for 0x5d for old NKEY keyboards until it is verified
> >>>>>> that it is not needed for their media keys to function.
> >>>>>> - Cover init in asus-wmi with spinlock as per Hans
> >>>>>> - If asus-wmi registers WMI handler with brightness, init the brightness
> >>>>>> in USB Asus keyboards, per Hans.
> >>>>>> - Change hid handler name to asus-UNIQ:rgb:peripheral to match led class
> >>>>>> - Fix oops when unregistering asus-wmi by moving unregister outside of
> >>>>>> the spin lock (but after the asus reference is set to null)
> >>>>>>
> >>>>>> Changes since V2:
> >>>>>> - Check lazy init succeds in asus-wmi before setting register variable
> >>>>>> - make explicit check in asus_hid_register_listener for listener existing
> >>>>>> to avoid re-init
> >>>>>> - rename asus_brt to asus_hid in most places and harmonize everything
> >>>>>> - switch to a spinlock instead of a mutex to avoid kernel ooops
> >>>>>> - fixup hid device quirks to avoid multiple RGB devices while still exposing
> >>>>>> all input vendor devices. This includes moving rgb init to probe
> >>>>>> instead of the input_configured callbacks.
> >>>>>> - Remove fan key (during retest it appears to be 0xae that is already
> >>>>>> supported by hid-asus)
> >>>>>> - Never unregister asus::kbd_backlight while asus-wmi is active, as that
> >>>>>> - removes fds from userspace and breaks backlight functionality. All
> >>>>>> - current mainline drivers do not support backlight hotplugging, so most
> >>>>>> userspace software (e.g., KDE, UPower) is built with that assumption.
> >>>>>> For the Ally, since it disconnects its controller during sleep, this
> >>>>>> caused the backlight slider to not work in KDE.
> >>>>>>
> >>>>>> Changes since V1:
> >>>>>> - Add basic RGB support on hid-asus, (Z13/Ally) tested in KDE/Z13
> >>>>>> - Fix ifdef else having an invalid signature (reported by kernel robot)
> >>>>>> - Restore input arguments to init and keyboard function so they can
> >>>>>> be re-used for RGB controls.
> >>>>>> - Remove Z13 delay (it did not work to fix the touchpad) and replace it
> >>>>>> with a HID_GROUP_GENERIC quirk to allow hid-multitouch to load. Squash
> >>>>>> keyboard rename into it.
> >>>>>> - Unregister brightness listener before removing work queue to avoid
> >>>>>> a race condition causing corruption
> >>>>>> - Remove spurious mutex unlock in asus_brt_event
> >>>>>> - Place mutex lock in kbd_led_set after LED_UNREGISTERING check to avoid
> >>>>>> relocking the mutex and causing a deadlock when unregistering leds
> >>>>>> - Add extra check during unregistering to avoid calling unregister when
> >>>>>> no led device is registered.
> >>>>>> - Temporarily HID_QUIRK_INPUT_PER_APP from the ROG endpoint as it causes
> >>>>>> the driver to create 4 RGB handlers per device. I also suspect some
> >>>>>> extra events sneak through (KDE had the @@@@@@).
> >>>>>>
> >>>>>> Antheas Kapenekakis (7):
> >>>>>> HID: asus: refactor init sequence per spec
> >>>>>> HID: asus: prevent binding to all HID devices on ROG
> >>>>>> platform/x86: asus-wmi: Add support for multiple kbd RGB handlers
> >>>>>> HID: asus: listen to the asus-wmi brightness device instead of
> >>>>>> creating one
> >>>>>> platform/x86: asus-wmi: remove unused keyboard backlight quirk
> >>>>>> platform/x86: asus-wmi: add keyboard brightness event handler
> >>>>>> HID: asus: add support for the asus-wmi brightness handler
> >>>>>>
> >>>>>> drivers/hid/hid-asus.c | 235 +++++++++++----------
> >>>>>> drivers/platform/x86/asus-wmi.c | 157 ++++++++++++--
> >>>>>> include/linux/platform_data/x86/asus-wmi.h | 69 +++---
> >>>>>> 3 files changed, 291 insertions(+), 170 deletions(-)
> >>>>>>
> >>>>>>
> >>>>>> base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
> >>>
>
^ permalink raw reply
* Re: [PATCH v6 0/7] HID: asus: Fix ASUS ROG Laptop's Keyboard backlight handling
From: Denis Benato @ 2025-10-17 11:00 UTC (permalink / raw)
To: Antheas Kapenekakis, Ilpo Järvinen
Cc: platform-driver-x86, linux-input, LKML, Jiri Kosina,
Benjamin Tissoires, Corentin Chary, Luke D . Jones, Hans de Goede
In-Reply-To: <CAGwozwGqZ_yuNQ+TgtW4R79g4JWxZg-Q-vA7thKy_vSdpbY_yA@mail.gmail.com>
On 10/17/25 09:54, Antheas Kapenekakis wrote:
> On Thu, 16 Oct 2025 at 18:16, Antheas Kapenekakis <lkml@antheas.dev> wrote:
>> On Thu, 16 Oct 2025 at 17:09, Ilpo Järvinen
>> <ilpo.jarvinen@linux.intel.com> wrote:
>>> On Thu, 16 Oct 2025, Antheas Kapenekakis wrote:
>>>> On Thu, 16 Oct 2025 at 13:57, Denis Benato <benato.denis96@gmail.com> wrote:
>>>>> On 10/13/25 22:15, Antheas Kapenekakis wrote:
>>>>>> This is a two part series which does the following:
>>>>>> - Clean-up init sequence
>>>>>> - Unify backlight handling to happen under asus-wmi so that all Aura
>>>>>> devices have synced brightness controls and the backlight button works
>>>>>> properly when it is on a USB laptop keyboard instead of one w/ WMI.
>>>>>>
>>>>>> For more context, see cover letter of V1. Since V5, I removed some patches
>>>>>> to make this easier to merge.
>>>>>>
>>>>>> All comments with these patches had been addressed since V4.
>>>>> I have loaded this patchset for users of asus-linux project to try out.
>>>>>
>>>>> One of them opened a bug report about a kernel bug that happens
>>>>> consistently when closing the lid of his laptop [1].
>>>>>
>>>>> He also sent another piece of kernel log, but didn't specify anything more
>>>>> about this [2].
>>>>>
>>>>> [1] https://pastebin.com/akZx1w10
>>>>> [2] https://pastebin.com/sKdczPgf
>>>> Can you provide a link to the bug report? [2] seems unrelated.
>>>>
>>>> As for [1], it looks like a trace that stems from a sysfs write to
>>>> brightness stemming from userspace that follows the same chain it
>>>> would on a stock kernel and times out. Is it present on a stock
>>>> kernel?
>>>>
>>>> Ilpo should know more about this, could the spinlock be interfering?
>>> [1] certainly seems to do schedule() from do_kbd_led_set() so it's not
>>> possible to use spinlock there.
>>>
>>> So we're back to what requires the spinlock? And what the spinlock
>>> protects?
>> For that invocation, since it is coming from the cdev device owned by
>> asus_wmi, it protects asus_ref.listeners under do_kbd_led_set.
>> asus_wmi is protected by the fact it is owned by that device. Spinlock
>> is not required in this invocation due to not being an IRQ.
>>
>> Under asus_hid_event (second to last patch), which is called from an
>> IRQ, a spinlock is required for protecting both listeners and the
>> asus_ref.asus, and I suspect that scheduling from an IRQ is not
>> allowed either. Is that correct?
> So it is a bit tricky here. When the IRQ fires, it needs to know
> whether asus-wmi will handle the keyboard brightness event so that it
> falls back to emitting it.
>
> If we want it to know for sure, it needs to access asus_wmi, so it
> needs a spinlock or an IRQ friendly lock. This way, currently,
> asus_hid_event will return -EBUSY if there is no led device so the
> event propagates through hid.
>
> If we say that it is good enough to know that it was compiled with
> IS_REACHABLE(CONFIG_ASUS_WMI), ie the actual implementation of
> asus_hid_event in asus-wmi will never return an error, then,
> asus_hid_event can schedule a task to fire the event without a lock,
> and that task can use a normal locking primitive.
>
> If the task needs to be assigned to a device or have a handle,
> asus_hid_listener can be provided to asus_hid_event, so that it is
> owned by the calling device.
>
> What would the appropriate locking primitive be in this case?
The right place to look into appears to be Documentation/kernel-hacking/locking.rst
I see mutex being used in various irq handlers, even bmi323-imu but that page has
many alternatives for irq.
There is rwlock_t but it appears to be using spinlock on certain configurations.
Absolute worst-case scenario you might resort implementing an rwlock with mutexes only.
I would avoid taking decisions based solely on the configuration because ASUS
makes keyboards and reuses designs across various products, so it is very likely
at least one model of those keyboards can be confused with a laptop one.
Beside I am sure there must be at the very least one appropriate synchronization primitive,
so I would discard the configure option.
>> Antheas
>>> Not related to this particular email in this thread, if the users are
>>> testing something with different kernels, it's also important to make sure
>>> that the lockdep configs are enabled in both. As it could be that in one
>>> kernel lockdep is not enabled and thus it won't do the splat.
>>>
>>> --
>>> i.
>>>
>>>
>>>> My testing on devices that have WMI led controls is a bit limited
>>>> unfortunately. However, most of our asus users have been happy with
>>>> this series for around half a year now.
>>>>
>>>>>> ---
>>>>>> V5: https://lore.kernel.org/all/20250325184601.10990-1-lkml@antheas.dev/
>>>>>> V4: https://lore.kernel.org/lkml/20250324210151.6042-1-lkml@antheas.dev/
>>>>>> V3: https://lore.kernel.org/lkml/20250322102804.418000-1-lkml@antheas.dev/
>>>>>> V2: https://lore.kernel.org/all/20250320220924.5023-1-lkml@antheas.dev/
>>>>>> V1: https://lore.kernel.org/all/20250319191320.10092-1-lkml@antheas.dev/
>>>>>>
>>>>>> Changes since V5:
>>>>>> - It's been a long time
>>>>>> - Remove addition of RGB as that had some comments I need to work on
>>>>>> - Remove folio patch (already merged)
>>>>>> - Remove legacy fix patch 11 from V4. There is a small chance that
>>>>>> without this patch, some old NKEY keyboards might not respond to
>>>>>> RGB commands according to Luke, but the kernel driver does not do
>>>>>> RGB currently. The 0x5d init is done by Armoury crate software in
>>>>>> Windows. If an issue is found, we can re-add it or just remove patches
>>>>>> 1/2 before merging. However, init could use the cleanup.
>>>>>>
>>>>>> Changes since V4:
>>>>>> - Fix KConfig (reported by kernel robot)
>>>>>> - Fix Ilpo's nits, if I missed anything lmk
>>>>>>
>>>>>> Changes since V3:
>>>>>> - Add initializer for 0x5d for old NKEY keyboards until it is verified
>>>>>> that it is not needed for their media keys to function.
>>>>>> - Cover init in asus-wmi with spinlock as per Hans
>>>>>> - If asus-wmi registers WMI handler with brightness, init the brightness
>>>>>> in USB Asus keyboards, per Hans.
>>>>>> - Change hid handler name to asus-UNIQ:rgb:peripheral to match led class
>>>>>> - Fix oops when unregistering asus-wmi by moving unregister outside of
>>>>>> the spin lock (but after the asus reference is set to null)
>>>>>>
>>>>>> Changes since V2:
>>>>>> - Check lazy init succeds in asus-wmi before setting register variable
>>>>>> - make explicit check in asus_hid_register_listener for listener existing
>>>>>> to avoid re-init
>>>>>> - rename asus_brt to asus_hid in most places and harmonize everything
>>>>>> - switch to a spinlock instead of a mutex to avoid kernel ooops
>>>>>> - fixup hid device quirks to avoid multiple RGB devices while still exposing
>>>>>> all input vendor devices. This includes moving rgb init to probe
>>>>>> instead of the input_configured callbacks.
>>>>>> - Remove fan key (during retest it appears to be 0xae that is already
>>>>>> supported by hid-asus)
>>>>>> - Never unregister asus::kbd_backlight while asus-wmi is active, as that
>>>>>> - removes fds from userspace and breaks backlight functionality. All
>>>>>> - current mainline drivers do not support backlight hotplugging, so most
>>>>>> userspace software (e.g., KDE, UPower) is built with that assumption.
>>>>>> For the Ally, since it disconnects its controller during sleep, this
>>>>>> caused the backlight slider to not work in KDE.
>>>>>>
>>>>>> Changes since V1:
>>>>>> - Add basic RGB support on hid-asus, (Z13/Ally) tested in KDE/Z13
>>>>>> - Fix ifdef else having an invalid signature (reported by kernel robot)
>>>>>> - Restore input arguments to init and keyboard function so they can
>>>>>> be re-used for RGB controls.
>>>>>> - Remove Z13 delay (it did not work to fix the touchpad) and replace it
>>>>>> with a HID_GROUP_GENERIC quirk to allow hid-multitouch to load. Squash
>>>>>> keyboard rename into it.
>>>>>> - Unregister brightness listener before removing work queue to avoid
>>>>>> a race condition causing corruption
>>>>>> - Remove spurious mutex unlock in asus_brt_event
>>>>>> - Place mutex lock in kbd_led_set after LED_UNREGISTERING check to avoid
>>>>>> relocking the mutex and causing a deadlock when unregistering leds
>>>>>> - Add extra check during unregistering to avoid calling unregister when
>>>>>> no led device is registered.
>>>>>> - Temporarily HID_QUIRK_INPUT_PER_APP from the ROG endpoint as it causes
>>>>>> the driver to create 4 RGB handlers per device. I also suspect some
>>>>>> extra events sneak through (KDE had the @@@@@@).
>>>>>>
>>>>>> Antheas Kapenekakis (7):
>>>>>> HID: asus: refactor init sequence per spec
>>>>>> HID: asus: prevent binding to all HID devices on ROG
>>>>>> platform/x86: asus-wmi: Add support for multiple kbd RGB handlers
>>>>>> HID: asus: listen to the asus-wmi brightness device instead of
>>>>>> creating one
>>>>>> platform/x86: asus-wmi: remove unused keyboard backlight quirk
>>>>>> platform/x86: asus-wmi: add keyboard brightness event handler
>>>>>> HID: asus: add support for the asus-wmi brightness handler
>>>>>>
>>>>>> drivers/hid/hid-asus.c | 235 +++++++++++----------
>>>>>> drivers/platform/x86/asus-wmi.c | 157 ++++++++++++--
>>>>>> include/linux/platform_data/x86/asus-wmi.h | 69 +++---
>>>>>> 3 files changed, 291 insertions(+), 170 deletions(-)
>>>>>>
>>>>>>
>>>>>> base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
>>>
^ permalink raw reply
* Re: [PATCH v6 0/7] HID: asus: Fix ASUS ROG Laptop's Keyboard backlight handling
From: Ilpo Järvinen @ 2025-10-17 10:36 UTC (permalink / raw)
To: Antheas Kapenekakis
Cc: Denis Benato, platform-driver-x86, linux-input, LKML, Jiri Kosina,
Benjamin Tissoires, Corentin Chary, Luke D . Jones, Hans de Goede
In-Reply-To: <CAGwozwH3VnTsx8p5N6S1yp4Z9mFfPUdZ4frrnPAveLH2a00K6g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2605 bytes --]
On Thu, 16 Oct 2025, Antheas Kapenekakis wrote:
> On Thu, 16 Oct 2025 at 17:09, Ilpo Järvinen
> > On Thu, 16 Oct 2025, Antheas Kapenekakis wrote:
> > > On Thu, 16 Oct 2025 at 13:57, Denis Benato <benato.denis96@gmail.com> wrote:
> > > > On 10/13/25 22:15, Antheas Kapenekakis wrote:
> > > > > This is a two part series which does the following:
> > > > > - Clean-up init sequence
> > > > > - Unify backlight handling to happen under asus-wmi so that all Aura
> > > > > devices have synced brightness controls and the backlight button works
> > > > > properly when it is on a USB laptop keyboard instead of one w/ WMI.
> > > > >
> > > > > For more context, see cover letter of V1. Since V5, I removed some patches
> > > > > to make this easier to merge.
> > > > >
> > > > > All comments with these patches had been addressed since V4.
> > > > I have loaded this patchset for users of asus-linux project to try out.
> > > >
> > > > One of them opened a bug report about a kernel bug that happens
> > > > consistently when closing the lid of his laptop [1].
> > > >
> > > > He also sent another piece of kernel log, but didn't specify anything more
> > > > about this [2].
> > > >
> > > > [1] https://pastebin.com/akZx1w10
> > > > [2] https://pastebin.com/sKdczPgf
> > >
> > > Can you provide a link to the bug report? [2] seems unrelated.
> > >
> > > As for [1], it looks like a trace that stems from a sysfs write to
> > > brightness stemming from userspace that follows the same chain it
> > > would on a stock kernel and times out. Is it present on a stock
> > > kernel?
> > >
> > > Ilpo should know more about this, could the spinlock be interfering?
> >
> > [1] certainly seems to do schedule() from do_kbd_led_set() so it's not
> > possible to use spinlock there.
> >
> > So we're back to what requires the spinlock? And what the spinlock
> > protects?
>
> For that invocation, since it is coming from the cdev device owned by
> asus_wmi, it protects asus_ref.listeners under do_kbd_led_set.
> asus_wmi is protected by the fact it is owned by that device. Spinlock
> is not required in this invocation due to not being an IRQ.
>
> Under asus_hid_event (second to last patch), which is called from an
> IRQ, a spinlock is required for protecting both listeners and the
> asus_ref.asus, and I suspect that scheduling from an IRQ is not
> allowed either. Is that correct?
Yes, it's not allowed either.
hid-asus seems to already use workqueue (though include for it is
missing) likely to workaround a similar challenge.
--
i.
^ permalink raw reply
* [PATCH v2 27/27 5.10.y] minmax.h: remove some #defines that are only expanded once
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter, Jens Axboe,
Lorenzo Stoakes, Mateusz Guzik, Pedro Falcato
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: David Laight <David.Laight@ACULAB.COM>
[ Upstream commit 2b97aaf74ed534fb838d09867d09a3ca5d795208 ]
The bodies of __signed_type_use() and __unsigned_type_use() are much the
same size as their names - so put the bodies in the only line that expands
them.
Similarly __signed_type() is defined separately for 64bit and then used
exactly once just below.
Change the test for __signed_type from CONFIG_64BIT to one based on gcc
defined macros so that the code is valid if it gets used outside of a
kernel build.
Link: https://lkml.kernel.org/r/9386d1ebb8974fbabbed2635160c3975@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 2bbdd5b5e07e..eaaf5c008e4d 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -46,10 +46,8 @@
* comparison, and these expressions only need to be careful to not cause
* warnings for pointer use.
*/
-#define __signed_type_use(ux) (2 + __is_nonneg(ux))
-#define __unsigned_type_use(ux) (1 + 2 * (sizeof(ux) < 4))
#define __sign_use(ux) (is_signed_type(typeof(ux)) ? \
- __signed_type_use(ux) : __unsigned_type_use(ux))
+ (2 + __is_nonneg(ux)) : (1 + 2 * (sizeof(ux) < 4)))
/*
* Check whether a signed value is always non-negative.
@@ -57,7 +55,7 @@
* A cast is needed to avoid any warnings from values that aren't signed
* integer types (in which case the result doesn't matter).
*
- * On 64-bit any integer or pointer type can safely be cast to 'long'.
+ * On 64-bit any integer or pointer type can safely be cast to 'long long'.
* But on 32-bit we need to avoid warnings about casting pointers to integers
* of different sizes without truncating 64-bit values so 'long' or 'long long'
* must be used depending on the size of the value.
@@ -66,12 +64,12 @@
* them, but we do not use s128 types in the kernel (we do use 'u128',
* but they are handled by the !is_signed_type() case).
*/
-#ifdef CONFIG_64BIT
- #define __signed_type(ux) long
+#if __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
+#define __is_nonneg(ux) statically_true((long long)(ux) >= 0)
#else
- #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L))
+#define __is_nonneg(ux) statically_true( \
+ (typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)))(ux) >= 0)
#endif
-#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >= 0)
#define __types_ok(ux, uy) \
(__sign_use(ux) & __sign_use(uy))
--
2.47.3
^ permalink raw reply related
* [PATCH v2 26/27 5.10.y] minmax.h: simplify the variants of clamp()
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter, Jens Axboe,
Lorenzo Stoakes, Mateusz Guzik, Pedro Falcato
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: David Laight <David.Laight@ACULAB.COM>
[ Upstream commit 495bba17cdf95e9703af1b8ef773c55ef0dfe703 ]
Always pass a 'type' through to __clamp_once(), pass '__auto_type' from
clamp() itself.
The expansion of __types_ok3() is reasonable so it isn't worth the added
complexity of avoiding it when a fixed type is used for all three values.
Link: https://lkml.kernel.org/r/8f69f4deac014f558bab186444bac2e8@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 75fb7a6ad4c6..2bbdd5b5e07e 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -183,29 +183,29 @@
#define __clamp(val, lo, hi) \
((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val)))
-#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \
- __auto_type uval = (val); \
- __auto_type ulo = (lo); \
- __auto_type uhi = (hi); \
+#define __clamp_once(type, val, lo, hi, uval, ulo, uhi) ({ \
+ type uval = (val); \
+ type ulo = (lo); \
+ type uhi = (hi); \
BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
"clamp() low limit " #lo " greater than high limit " #hi); \
BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \
"clamp("#val", "#lo", "#hi") signedness error"); \
__clamp(uval, ulo, uhi); })
-#define __careful_clamp(val, lo, hi) \
- __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
+#define __careful_clamp(type, val, lo, hi) \
+ __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
/**
- * clamp - return a value clamped to a given range with strict typechecking
+ * clamp - return a value clamped to a given range with typechecking
* @val: current value
* @lo: lowest allowable value
* @hi: highest allowable value
*
- * This macro does strict typechecking of @lo/@hi to make sure they are of the
- * same type as @val. See the unnecessary pointer comparisons.
+ * This macro checks @val/@lo/@hi to make sure they have compatible
+ * signedness.
*/
-#define clamp(val, lo, hi) __careful_clamp(val, lo, hi)
+#define clamp(val, lo, hi) __careful_clamp(__auto_type, val, lo, hi)
/**
* clamp_t - return a value clamped to a given range using a given type
@@ -217,7 +217,7 @@
* This macro does no typechecking and uses temporary variables of type
* @type to make all the comparisons.
*/
-#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi))
+#define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi)
/**
* clamp_val - return a value clamped to a given range using val's type
@@ -230,7 +230,7 @@
* type and @lo and @hi are literals that will otherwise be assigned a signed
* integer type.
*/
-#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
+#define clamp_val(val, lo, hi) __careful_clamp(typeof(val), val, lo, hi)
/*
* Do not check the array parameter using __must_be_array().
--
2.47.3
^ permalink raw reply related
* [PATCH v2 25/27 5.10.y] minmax.h: move all the clamp() definitions after the min/max() ones
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter, Jens Axboe,
Lorenzo Stoakes, Mateusz Guzik, Pedro Falcato
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: David Laight <David.Laight@ACULAB.COM>
[ Upstream commit c3939872ee4a6b8bdcd0e813c66823b31e6e26f7 ]
At some point the definitions for clamp() got added in the middle of the
ones for min() and max(). Re-order the definitions so they are more
sensibly grouped.
Link: https://lkml.kernel.org/r/8bb285818e4846469121c8abc3dfb6e2@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 109 +++++++++++++++++++----------------------
1 file changed, 51 insertions(+), 58 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 91aa1b90c1bb..75fb7a6ad4c6 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -99,22 +99,6 @@
#define __careful_cmp(op, x, y) \
__careful_cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_))
-#define __clamp(val, lo, hi) \
- ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val)))
-
-#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \
- __auto_type uval = (val); \
- __auto_type ulo = (lo); \
- __auto_type uhi = (hi); \
- BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
- "clamp() low limit " #lo " greater than high limit " #hi); \
- BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \
- "clamp("#val", "#lo", "#hi") signedness error"); \
- __clamp(uval, ulo, uhi); })
-
-#define __careful_clamp(val, lo, hi) \
- __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
-
/**
* min - return minimum of two values of the same or compatible types
* @x: first value
@@ -170,6 +154,22 @@
#define max3(x, y, z) \
__careful_op3(max, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_))
+/**
+ * min_t - return minimum of two values, using the specified type
+ * @type: data type to use
+ * @x: first value
+ * @y: second value
+ */
+#define min_t(type, x, y) __cmp_once(min, type, x, y)
+
+/**
+ * max_t - return maximum of two values, using the specified type
+ * @type: data type to use
+ * @x: first value
+ * @y: second value
+ */
+#define max_t(type, x, y) __cmp_once(max, type, x, y)
+
/**
* min_not_zero - return the minimum that is _not_ zero, unless both are zero
* @x: value1
@@ -180,6 +180,22 @@
typeof(y) __y = (y); \
__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
+#define __clamp(val, lo, hi) \
+ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val)))
+
+#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \
+ __auto_type uval = (val); \
+ __auto_type ulo = (lo); \
+ __auto_type uhi = (hi); \
+ BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
+ "clamp() low limit " #lo " greater than high limit " #hi); \
+ BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \
+ "clamp("#val", "#lo", "#hi") signedness error"); \
+ __clamp(uval, ulo, uhi); })
+
+#define __careful_clamp(val, lo, hi) \
+ __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
+
/**
* clamp - return a value clamped to a given range with strict typechecking
* @val: current value
@@ -191,28 +207,30 @@
*/
#define clamp(val, lo, hi) __careful_clamp(val, lo, hi)
-/*
- * ..and if you can't take the strict
- * types, you can specify one yourself.
- *
- * Or not use min/max/clamp at all, of course.
- */
-
/**
- * min_t - return minimum of two values, using the specified type
- * @type: data type to use
- * @x: first value
- * @y: second value
+ * clamp_t - return a value clamped to a given range using a given type
+ * @type: the type of variable to use
+ * @val: current value
+ * @lo: minimum allowable value
+ * @hi: maximum allowable value
+ *
+ * This macro does no typechecking and uses temporary variables of type
+ * @type to make all the comparisons.
*/
-#define min_t(type, x, y) __cmp_once(min, type, x, y)
+#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi))
/**
- * max_t - return maximum of two values, using the specified type
- * @type: data type to use
- * @x: first value
- * @y: second value
+ * clamp_val - return a value clamped to a given range using val's type
+ * @val: current value
+ * @lo: minimum allowable value
+ * @hi: maximum allowable value
+ *
+ * This macro does no typechecking and uses temporary variables of whatever
+ * type the input argument @val is. This is useful when @val is an unsigned
+ * type and @lo and @hi are literals that will otherwise be assigned a signed
+ * integer type.
*/
-#define max_t(type, x, y) __cmp_once(max, type, x, y)
+#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
/*
* Do not check the array parameter using __must_be_array().
@@ -257,31 +275,6 @@
*/
#define max_array(array, len) __minmax_array(max, array, len)
-/**
- * clamp_t - return a value clamped to a given range using a given type
- * @type: the type of variable to use
- * @val: current value
- * @lo: minimum allowable value
- * @hi: maximum allowable value
- *
- * This macro does no typechecking and uses temporary variables of type
- * @type to make all the comparisons.
- */
-#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi))
-
-/**
- * clamp_val - return a value clamped to a given range using val's type
- * @val: current value
- * @lo: minimum allowable value
- * @hi: maximum allowable value
- *
- * This macro does no typechecking and uses temporary variables of whatever
- * type the input argument @val is. This is useful when @val is an unsigned
- * type and @lo and @hi are literals that will otherwise be assigned a signed
- * integer type.
- */
-#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
-
static inline bool in_range64(u64 val, u64 start, u64 len)
{
return (val - start) < len;
--
2.47.3
^ permalink raw reply related
* [PATCH v2 24/27 5.10.y] minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp()
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter, Jens Axboe,
Lorenzo Stoakes, Mateusz Guzik, Pedro Falcato
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: David Laight <David.Laight@ACULAB.COM>
[ Upstream commit a5743f32baec4728711bbc01d6ac2b33d4c67040 ]
Use BUILD_BUG_ON_MSG(statically_true(ulo > uhi), ...) for the sanity check
of the bounds in clamp(). Gives better error coverage and one less
expansion of the arguments.
Link: https://lkml.kernel.org/r/34d53778977747f19cce2abb287bb3e6@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 6f7ea669d305..91aa1b90c1bb 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -106,8 +106,7 @@
__auto_type uval = (val); \
__auto_type ulo = (lo); \
__auto_type uhi = (hi); \
- static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \
- (lo) <= (hi), true), \
+ BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \
"clamp() low limit " #lo " greater than high limit " #hi); \
BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \
"clamp("#val", "#lo", "#hi") signedness error"); \
--
2.47.3
^ permalink raw reply related
* [PATCH v2 23/27 5.10.y] minmax.h: reduce the #define expansion of min(), max() and clamp()
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter, Jens Axboe,
Lorenzo Stoakes, Mateusz Guzik, Pedro Falcato
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: David Laight <David.Laight@ACULAB.COM>
[ Upstream commit b280bb27a9f7c91ddab730e1ad91a9c18a051f41 ]
Since the test for signed values being non-negative only relies on
__builtion_constant_p() (not is_constexpr()) it can use the 'ux' variable
instead of the caller supplied expression. This means that the #define
parameters are only expanded twice. Once in the code and once quoted in
the error message.
Link: https://lkml.kernel.org/r/051afc171806425da991908ed8688a98@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 24e4b372649a..6f7ea669d305 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -46,10 +46,10 @@
* comparison, and these expressions only need to be careful to not cause
* warnings for pointer use.
*/
-#define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux))
-#define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4))
-#define __sign_use(x, ux) (is_signed_type(typeof(ux)) ? \
- __signed_type_use(x, ux) : __unsigned_type_use(x, ux))
+#define __signed_type_use(ux) (2 + __is_nonneg(ux))
+#define __unsigned_type_use(ux) (1 + 2 * (sizeof(ux) < 4))
+#define __sign_use(ux) (is_signed_type(typeof(ux)) ? \
+ __signed_type_use(ux) : __unsigned_type_use(ux))
/*
* Check whether a signed value is always non-negative.
@@ -71,13 +71,13 @@
#else
#define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L))
#endif
-#define __is_nonneg(x, ux) statically_true((__signed_type(ux))(x) >= 0)
+#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >= 0)
-#define __types_ok(x, y, ux, uy) \
- (__sign_use(x, ux) & __sign_use(y, uy))
+#define __types_ok(ux, uy) \
+ (__sign_use(ux) & __sign_use(uy))
-#define __types_ok3(x, y, z, ux, uy, uz) \
- (__sign_use(x, ux) & __sign_use(y, uy) & __sign_use(z, uz))
+#define __types_ok3(ux, uy, uz) \
+ (__sign_use(ux) & __sign_use(uy) & __sign_use(uz))
#define __cmp_op_min <
#define __cmp_op_max >
@@ -92,7 +92,7 @@
#define __careful_cmp_once(op, x, y, ux, uy) ({ \
__auto_type ux = (x); __auto_type uy = (y); \
- BUILD_BUG_ON_MSG(!__types_ok(x, y, ux, uy), \
+ BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \
#op"("#x", "#y") signedness error"); \
__cmp(op, ux, uy); })
@@ -109,7 +109,7 @@
static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \
(lo) <= (hi), true), \
"clamp() low limit " #lo " greater than high limit " #hi); \
- BUILD_BUG_ON_MSG(!__types_ok3(val, lo, hi, uval, ulo, uhi), \
+ BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \
"clamp("#val", "#lo", "#hi") signedness error"); \
__clamp(uval, ulo, uhi); })
@@ -149,7 +149,7 @@
#define __careful_op3(op, x, y, z, ux, uy, uz) ({ \
__auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\
- BUILD_BUG_ON_MSG(!__types_ok3(x, y, z, ux, uy, uz), \
+ BUILD_BUG_ON_MSG(!__types_ok3(ux, uy, uz), \
#op"3("#x", "#y", "#z") signedness error"); \
__cmp(op, ux, __cmp(op, uy, uz)); })
--
2.47.3
^ permalink raw reply related
* [PATCH v2 22/27 5.10.y] minmax.h: update some comments
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter, Jens Axboe,
Lorenzo Stoakes, Mateusz Guzik, Pedro Falcato
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: David Laight <David.Laight@ACULAB.COM>
[ Upstream commit 10666e99204818ef45c702469488353b5bb09ec7 ]
- Change three to several.
- Remove the comment about retaining constant expressions, no longer true.
- Realign to nearer 80 columns and break on major punctiation.
- Add a leading comment to the block before __signed_type() and __is_nonneg()
Otherwise the block explaining the cast is a bit 'floating'.
Reword the rest of that comment to improve readability.
Link: https://lkml.kernel.org/r/85b050c81c1d4076aeb91a6cded45fee@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 53 +++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 29 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 51b0d988e322..24e4b372649a 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -8,13 +8,10 @@
#include <linux/types.h>
/*
- * min()/max()/clamp() macros must accomplish three things:
+ * min()/max()/clamp() macros must accomplish several things:
*
* - Avoid multiple evaluations of the arguments (so side-effects like
* "x++" happen only once) when non-constant.
- * - Retain result as a constant expressions when called with only
- * constant expressions (to avoid tripping VLA warnings in stack
- * allocation usage).
* - Perform signed v unsigned type-checking (to generate compile
* errors instead of nasty runtime surprises).
* - Unsigned char/short are always promoted to signed int and can be
@@ -31,25 +28,23 @@
* bit #0 set if ok for unsigned comparisons
* bit #1 set if ok for signed comparisons
*
- * In particular, statically non-negative signed integer
- * expressions are ok for both.
+ * In particular, statically non-negative signed integer expressions
+ * are ok for both.
*
- * NOTE! Unsigned types smaller than 'int' are implicitly
- * converted to 'int' in expressions, and are accepted for
- * signed conversions for now. This is debatable.
+ * NOTE! Unsigned types smaller than 'int' are implicitly converted to 'int'
+ * in expressions, and are accepted for signed conversions for now.
+ * This is debatable.
*
- * Note that 'x' is the original expression, and 'ux' is
- * the unique variable that contains the value.
+ * Note that 'x' is the original expression, and 'ux' is the unique variable
+ * that contains the value.
*
- * We use 'ux' for pure type checking, and 'x' for when
- * we need to look at the value (but without evaluating
- * it for side effects! Careful to only ever evaluate it
- * with sizeof() or __builtin_constant_p() etc).
+ * We use 'ux' for pure type checking, and 'x' for when we need to look at the
+ * value (but without evaluating it for side effects!
+ * Careful to only ever evaluate it with sizeof() or __builtin_constant_p() etc).
*
- * Pointers end up being checked by the normal C type
- * rules at the actual comparison, and these expressions
- * only need to be careful to not cause warnings for
- * pointer use.
+ * Pointers end up being checked by the normal C type rules at the actual
+ * comparison, and these expressions only need to be careful to not cause
+ * warnings for pointer use.
*/
#define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux))
#define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4))
@@ -57,19 +52,19 @@
__signed_type_use(x, ux) : __unsigned_type_use(x, ux))
/*
- * To avoid warnings about casting pointers to integers
- * of different sizes, we need that special sign type.
+ * Check whether a signed value is always non-negative.
*
- * On 64-bit we can just always use 'long', since any
- * integer or pointer type can just be cast to that.
+ * A cast is needed to avoid any warnings from values that aren't signed
+ * integer types (in which case the result doesn't matter).
*
- * This does not work for 128-bit signed integers since
- * the cast would truncate them, but we do not use s128
- * types in the kernel (we do use 'u128', but they will
- * be handled by the !is_signed_type() case).
+ * On 64-bit any integer or pointer type can safely be cast to 'long'.
+ * But on 32-bit we need to avoid warnings about casting pointers to integers
+ * of different sizes without truncating 64-bit values so 'long' or 'long long'
+ * must be used depending on the size of the value.
*
- * NOTE! The cast is there only to avoid any warnings
- * from when values that aren't signed integer types.
+ * This does not work for 128-bit signed integers since the cast would truncate
+ * them, but we do not use s128 types in the kernel (we do use 'u128',
+ * but they are handled by the !is_signed_type() case).
*/
#ifdef CONFIG_64BIT
#define __signed_type(ux) long
--
2.47.3
^ permalink raw reply related
* [PATCH v2 21/27 5.10.y] minmax.h: add whitespace around operators and after commas
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter, Jens Axboe,
Lorenzo Stoakes, Mateusz Guzik, Pedro Falcato
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: David Laight <David.Laight@ACULAB.COM>
[ Upstream commit 71ee9b16251ea4bf7c1fe222517c82bdb3220acc ]
Patch series "minmax.h: Cleanups and minor optimisations".
Some tidyups and minor changes to minmax.h.
This patch (of 7):
Link: https://lkml.kernel.org/r/c50365d214e04f9ba256d417c8bebbc0@AcuMS.aculab.com
Link: https://lkml.kernel.org/r/f04b2e1310244f62826267346fde0553@AcuMS.aculab.com
Signed-off-by: David Laight <david.laight@aculab.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 98008dd92153..51b0d988e322 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -51,10 +51,10 @@
* only need to be careful to not cause warnings for
* pointer use.
*/
-#define __signed_type_use(x,ux) (2+__is_nonneg(x,ux))
-#define __unsigned_type_use(x,ux) (1+2*(sizeof(ux)<4))
-#define __sign_use(x,ux) (is_signed_type(typeof(ux))? \
- __signed_type_use(x,ux):__unsigned_type_use(x,ux))
+#define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux))
+#define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4))
+#define __sign_use(x, ux) (is_signed_type(typeof(ux)) ? \
+ __signed_type_use(x, ux) : __unsigned_type_use(x, ux))
/*
* To avoid warnings about casting pointers to integers
@@ -74,15 +74,15 @@
#ifdef CONFIG_64BIT
#define __signed_type(ux) long
#else
- #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux)>4,1LL,1L))
+ #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L))
#endif
-#define __is_nonneg(x,ux) statically_true((__signed_type(ux))(x)>=0)
+#define __is_nonneg(x, ux) statically_true((__signed_type(ux))(x) >= 0)
-#define __types_ok(x,y,ux,uy) \
- (__sign_use(x,ux) & __sign_use(y,uy))
+#define __types_ok(x, y, ux, uy) \
+ (__sign_use(x, ux) & __sign_use(y, uy))
-#define __types_ok3(x,y,z,ux,uy,uz) \
- (__sign_use(x,ux) & __sign_use(y,uy) & __sign_use(z,uz))
+#define __types_ok3(x, y, z, ux, uy, uz) \
+ (__sign_use(x, ux) & __sign_use(y, uy) & __sign_use(z, uz))
#define __cmp_op_min <
#define __cmp_op_max >
@@ -97,7 +97,7 @@
#define __careful_cmp_once(op, x, y, ux, uy) ({ \
__auto_type ux = (x); __auto_type uy = (y); \
- BUILD_BUG_ON_MSG(!__types_ok(x,y,ux,uy), \
+ BUILD_BUG_ON_MSG(!__types_ok(x, y, ux, uy), \
#op"("#x", "#y") signedness error"); \
__cmp(op, ux, uy); })
@@ -114,7 +114,7 @@
static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \
(lo) <= (hi), true), \
"clamp() low limit " #lo " greater than high limit " #hi); \
- BUILD_BUG_ON_MSG(!__types_ok3(val,lo,hi,uval,ulo,uhi), \
+ BUILD_BUG_ON_MSG(!__types_ok3(val, lo, hi, uval, ulo, uhi), \
"clamp("#val", "#lo", "#hi") signedness error"); \
__clamp(uval, ulo, uhi); })
@@ -154,7 +154,7 @@
#define __careful_op3(op, x, y, z, ux, uy, uz) ({ \
__auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\
- BUILD_BUG_ON_MSG(!__types_ok3(x,y,z,ux,uy,uz), \
+ BUILD_BUG_ON_MSG(!__types_ok3(x, y, z, ux, uy, uz), \
#op"3("#x", "#y", "#z") signedness error"); \
__cmp(op, ux, __cmp(op, uy, uz)); })
@@ -326,9 +326,9 @@ static inline bool in_range32(u32 val, u32 start, u32 len)
* Use these carefully: no type checking, and uses the arguments
* multiple times. Use for obvious constants only.
*/
-#define MIN(a,b) __cmp(min,a,b)
-#define MAX(a,b) __cmp(max,a,b)
-#define MIN_T(type,a,b) __cmp(min,(type)(a),(type)(b))
-#define MAX_T(type,a,b) __cmp(max,(type)(a),(type)(b))
+#define MIN(a, b) __cmp(min, a, b)
+#define MAX(a, b) __cmp(max, a, b)
+#define MIN_T(type, a, b) __cmp(min, (type)(a), (type)(b))
+#define MAX_T(type, a, b) __cmp(max, (type)(a), (type)(b))
#endif /* _LINUX_MINMAX_H */
--
2.47.3
^ permalink raw reply related
* [PATCH v2 20/27 5.10.y] minmax: fix up min3() and max3() too
From: Eliav Farber @ 2025-10-17 9:05 UTC (permalink / raw)
To: gregkh, stable, linux, jdike, richard, anton.ivanov, dave.hansen,
luto, peterz, tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo,
mchehab, james.morse, rric, harry.wentland, sunpeng.li,
alexander.deucher, christian.koenig, airlied, daniel, evan.quan,
james.qian.wang, liviu.dudau, mihail.atanassov, brian.starkey,
maarten.lankhorst, mripard, tzimmermann, robdclark, sean,
jdelvare, linux, fery, dmitry.torokhov, agk, snitzer, dm-devel,
rajur, davem, kuba, peppe.cavallaro, alexandre.torgue, joabreu,
mcoquelin.stm32, malattia, hdegoede, mgross, intel-linux-scu,
artur.paszkiewicz, jejb, martin.petersen, sakari.ailus, clm,
josef, dsterba, xiang, chao, jack, tytso, adilger.kernel,
dushistov, luc.vanoostenryck, rostedt, pmladek,
sergey.senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
akpm, kuznet, yoshfuji, pablo, kadlec, fw, jmaloy, ying.xue,
willy, farbere, sashal, ruanjinjie, David.Laight, herve.codina,
Jason, keescook, kbusch, nathan, bvanassche, ndesaulniers,
linux-arm-kernel, linux-kernel, linux-um, linux-edac, amd-gfx,
dri-devel, linux-arm-msm, freedreno, linux-hwmon, linux-input,
linux-media, netdev, linux-stm32, platform-driver-x86, linux-scsi,
linux-staging, linux-btrfs, linux-erofs, linux-ext4, linux-sparse,
linux-mm, netfilter-devel, coreteam, tipc-discussion
Cc: Linus Torvalds, David Laight, Arnd Bergmann
In-Reply-To: <20251017090519.46992-1-farbere@amazon.com>
From: Linus Torvalds <torvalds@linux-foundation.org>
[ Upstream commit 21b136cc63d2a9ddd60d4699552b69c214b32964 ]
David Laight pointed out that we should deal with the min3() and max3()
mess too, which still does excessive expansion.
And our current macros are actually rather broken.
In particular, the macros did this:
#define min3(x, y, z) min((typeof(x))min(x, y), z)
#define max3(x, y, z) max((typeof(x))max(x, y), z)
and that not only is a nested expansion of possibly very complex
arguments with all that involves, the typing with that "typeof()" cast
is completely wrong.
For example, imagine what happens in max3() if 'x' happens to be a
'unsigned char', but 'y' and 'z' are 'unsigned long'. The types are
compatible, and there's no warning - but the result is just random
garbage.
No, I don't think we've ever hit that issue in practice, but since we
now have sane infrastructure for doing this right, let's just use it.
It fixes any excessive expansion, and also avoids these kinds of broken
type issues.
Requested-by: David Laight <David.Laight@aculab.com>
Acked-by: Arnd Bergmann <arnd@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/minmax.h | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 41da6f85a407..98008dd92153 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -152,13 +152,20 @@
#define umax(x, y) \
__careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)
+#define __careful_op3(op, x, y, z, ux, uy, uz) ({ \
+ __auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\
+ BUILD_BUG_ON_MSG(!__types_ok3(x,y,z,ux,uy,uz), \
+ #op"3("#x", "#y", "#z") signedness error"); \
+ __cmp(op, ux, __cmp(op, uy, uz)); })
+
/**
* min3 - return minimum of three values
* @x: first value
* @y: second value
* @z: third value
*/
-#define min3(x, y, z) min((typeof(x))min(x, y), z)
+#define min3(x, y, z) \
+ __careful_op3(min, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_))
/**
* max3 - return maximum of three values
@@ -166,7 +173,8 @@
* @y: second value
* @z: third value
*/
-#define max3(x, y, z) max((typeof(x))max(x, y), z)
+#define max3(x, y, z) \
+ __careful_op3(max, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_))
/**
* min_not_zero - return the minimum that is _not_ zero, unless both are zero
--
2.47.3
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox