Linux Input/HID development
 help / color / mirror / Atom feed
* [dtor-input:for-linus] BUILD SUCCESS 8b87f67b4c87452e21721887fa8dec1f4c6b2b7c
From: kernel test robot @ 2025-10-09 20:53 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input

tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git for-linus
branch HEAD: 8b87f67b4c87452e21721887fa8dec1f4c6b2b7c  Merge branch 'next' into for-linus

elapsed time: 843m

configs tested: 142
configs skipped: 4

The following configs have been built successfully.
More configs may be tested in the coming days.

tested configs:
alpha                             allnoconfig    clang-22
alpha                            allyesconfig    clang-19
alpha                               defconfig    clang-19
arc                              allmodconfig    clang-19
arc                               allnoconfig    clang-22
arc                              allyesconfig    clang-19
arc                          axs101_defconfig    gcc-15.1.0
arc                                 defconfig    clang-19
arm                              allmodconfig    clang-19
arm                               allnoconfig    clang-22
arm                              allyesconfig    clang-19
arm                                 defconfig    clang-19
arm                       imx_v4_v5_defconfig    gcc-15.1.0
arm64                            allmodconfig    clang-19
arm64                             allnoconfig    clang-22
arm64                               defconfig    clang-19
csky                              allnoconfig    clang-22
csky                                defconfig    clang-19
csky                  randconfig-001-20251009    clang-16
csky                  randconfig-002-20251009    clang-16
hexagon                          allmodconfig    clang-19
hexagon                           allnoconfig    clang-22
hexagon                          allyesconfig    clang-19
hexagon                             defconfig    clang-19
hexagon               randconfig-001-20251009    clang-16
hexagon               randconfig-002-20251009    clang-16
i386                             allmodconfig    clang-20
i386                              allnoconfig    clang-20
i386                             allyesconfig    clang-20
i386        buildonly-randconfig-001-20251009    gcc-14
i386        buildonly-randconfig-002-20251009    gcc-14
i386        buildonly-randconfig-003-20251009    gcc-14
i386        buildonly-randconfig-004-20251009    gcc-14
i386        buildonly-randconfig-005-20251009    gcc-14
i386        buildonly-randconfig-006-20251009    gcc-14
i386                                defconfig    clang-20
i386                  randconfig-001-20251010    clang-20
i386                  randconfig-002-20251010    clang-20
i386                  randconfig-003-20251010    clang-20
i386                  randconfig-004-20251010    clang-20
i386                  randconfig-005-20251010    clang-20
i386                  randconfig-006-20251010    clang-20
i386                  randconfig-007-20251010    clang-20
i386                  randconfig-011-20251009    clang-20
i386                  randconfig-012-20251009    clang-20
i386                  randconfig-013-20251009    clang-20
i386                  randconfig-014-20251009    clang-20
i386                  randconfig-015-20251009    clang-20
i386                  randconfig-016-20251009    clang-20
i386                  randconfig-017-20251009    clang-20
loongarch                        allmodconfig    clang-19
loongarch                         allnoconfig    clang-22
loongarch                           defconfig    clang-19
loongarch             randconfig-001-20251009    clang-16
loongarch             randconfig-002-20251009    clang-16
m68k                             allmodconfig    clang-19
m68k                              allnoconfig    gcc-15.1.0
m68k                             allyesconfig    clang-19
m68k                                defconfig    clang-19
m68k                          hp300_defconfig    gcc-15.1.0
m68k                        m5272c3_defconfig    gcc-15.1.0
microblaze                       allmodconfig    clang-19
microblaze                        allnoconfig    gcc-15.1.0
microblaze                       allyesconfig    clang-19
microblaze                          defconfig    gcc-15.1.0
mips                              allnoconfig    gcc-15.1.0
nios2                             allnoconfig    gcc-15.1.0
nios2                               defconfig    gcc-15.1.0
nios2                 randconfig-001-20251009    clang-16
nios2                 randconfig-002-20251009    clang-16
openrisc                          allnoconfig    clang-22
openrisc                         allyesconfig    gcc-15.1.0
parisc                           allmodconfig    gcc-15.1.0
parisc                            allnoconfig    clang-22
parisc                           allyesconfig    gcc-15.1.0
parisc                              defconfig    gcc-15.1.0
parisc                randconfig-001-20251009    clang-16
parisc                randconfig-002-20251009    clang-16
parisc64                            defconfig    gcc-15.1.0
powerpc                          allmodconfig    gcc-15.1.0
powerpc                           allnoconfig    clang-22
powerpc                          allyesconfig    gcc-15.1.0
powerpc                        icon_defconfig    gcc-15.1.0
powerpc               randconfig-001-20251009    clang-16
powerpc               randconfig-002-20251009    clang-16
powerpc               randconfig-003-20251009    clang-16
powerpc64             randconfig-002-20251009    clang-16
powerpc64             randconfig-003-20251009    clang-16
riscv                            allmodconfig    gcc-15.1.0
riscv                             allnoconfig    clang-22
riscv                            allyesconfig    gcc-15.1.0
riscv                 randconfig-001-20251009    clang-22
riscv                 randconfig-002-20251009    clang-22
s390                             alldefconfig    gcc-15.1.0
s390                             allmodconfig    gcc-15.1.0
s390                              allnoconfig    clang-22
s390                             allyesconfig    gcc-15.1.0
s390                  randconfig-001-20251009    clang-22
s390                  randconfig-002-20251009    clang-22
sh                               allmodconfig    gcc-15.1.0
sh                                allnoconfig    gcc-15.1.0
sh                               allyesconfig    gcc-15.1.0
sh                         ecovec24_defconfig    gcc-15.1.0
sh                    randconfig-001-20251009    clang-22
sh                    randconfig-002-20251009    clang-22
sparc                            allmodconfig    gcc-15.1.0
sparc                             allnoconfig    gcc-15.1.0
sparc                               defconfig    gcc-15.1.0
sparc                 randconfig-001-20251009    clang-22
sparc                 randconfig-002-20251009    clang-22
sparc64               randconfig-001-20251009    clang-22
sparc64               randconfig-002-20251009    clang-22
um                               allmodconfig    clang-19
um                                allnoconfig    clang-22
um                               allyesconfig    clang-19
um                    randconfig-001-20251009    clang-22
um                    randconfig-002-20251009    clang-22
x86_64                            allnoconfig    clang-20
x86_64                           allyesconfig    clang-20
x86_64      buildonly-randconfig-001-20251009    clang-20
x86_64      buildonly-randconfig-002-20251009    clang-20
x86_64      buildonly-randconfig-003-20251009    clang-20
x86_64      buildonly-randconfig-004-20251009    clang-20
x86_64      buildonly-randconfig-005-20251009    clang-20
x86_64      buildonly-randconfig-006-20251009    clang-20
x86_64                              defconfig    clang-20
x86_64                                  kexec    clang-20
x86_64                randconfig-071-20251009    gcc-14
x86_64                randconfig-072-20251009    gcc-14
x86_64                randconfig-073-20251009    gcc-14
x86_64                randconfig-074-20251009    gcc-14
x86_64                randconfig-075-20251009    gcc-14
x86_64                randconfig-076-20251009    gcc-14
x86_64                randconfig-077-20251009    gcc-14
x86_64                randconfig-078-20251009    gcc-14
x86_64                               rhel-9.4    clang-20
x86_64                          rhel-9.4-func    clang-20
x86_64                    rhel-9.4-kselftests    clang-20
x86_64                          rhel-9.4-rust    clang-20
xtensa                            allnoconfig    gcc-15.1.0
xtensa                randconfig-001-20251009    clang-22
xtensa                randconfig-002-20251009    clang-22

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply

* Re: [PATCH v3 2/2] dt-bindings: touchscreen: consolidate simple touch controller to trivial-touch.yaml
From: Rob Herring (Arm) @ 2025-10-09 18:09 UTC (permalink / raw)
  To: Frank Li
  Cc: Dmitry Torokhov, Job Noorman, imx, linux-input, devicetree,
	Krzysztof Kozlowski, linux-kernel, Conor Dooley
In-Reply-To: <20251002164413.1112136-2-Frank.Li@nxp.com>


On Thu, 02 Oct 2025 12:44:05 -0400, Frank Li wrote:
> Move ar1021.txt, azoteq,iqs5xx.yaml, himax,hx83112b.yaml,
> hynitron,cstxxx.yaml, ilitek_ts_i2c.yaml, semtech,sx8654.yaml, ar1021.txt
> to trivial-touch.yaml to consolidate simple touch yaml binding to one file.
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> change in v3
>  move more files into trivial-touch.yaml
>  don't add rob's review by because big change
>  prevous discussion at
>  https://lore.kernel.org/imx/175937443731.2982292.3723741722041625819.robh@kernel.org/T/#m35cfaaee8239b7a9aad3354b80de5f44d267c2e9
> 
> change in v2
>  move to trivial-touch.yaml
> 
> previous discussion
>     https://lore.kernel.org/imx/20250925-swimming-overspend-ddf7ab4a252c@spud/T/#t
> ---
>  .../bindings/input/touchscreen/ar1021.txt     | 15 ----
>  .../input/touchscreen/azoteq,iqs5xx.yaml      | 75 ------------------
>  .../input/touchscreen/himax,hx83112b.yaml     | 64 ----------------
>  .../input/touchscreen/hynitron,cstxxx.yaml    | 65 ----------------
>  .../input/touchscreen/ilitek_ts_i2c.yaml      | 76 -------------------
>  .../input/touchscreen/semtech,sx8654.yaml     | 52 -------------
>  .../input/touchscreen/trivial-touch.yaml      | 31 ++++++++
>  7 files changed, 31 insertions(+), 347 deletions(-)
>  delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/ar1021.txt
>  delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/azoteq,iqs5xx.yaml
>  delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml
>  delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/hynitron,cstxxx.yaml
>  delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/ilitek_ts_i2c.yaml
>  delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/semtech,sx8654.yaml
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


^ permalink raw reply

* Re: [PATCH v2] input: goodix: Remove setting of RST pin to input
From: Hans de Goede @ 2025-10-09 17:51 UTC (permalink / raw)
  To: Martyn Welch, Dmitry Torokhov; +Cc: kernel, linux-input, linux-kernel
In-Reply-To: <20251009134138.686215-1-martyn.welch@collabora.com>

Hi,

On 9-Oct-25 3:41 PM, Martyn Welch wrote:
> The reset line is being set to input on non-ACPI devices apparently to
> save power. This isn't being done on ACPI devices as it's been found
> that some ACPI devices don't have a pull-up resistor fitted. This can
> also be the case for non-ACPI devices, resulting in:
> 
> [  941.672207] Goodix-TS 1-0014: Error reading 10 bytes from 0x814e: -110
> [  942.696168] Goodix-TS 1-0014: Error reading 10 bytes from 0x814e: -110
> [  945.832208] Goodix-TS 1-0014: Error reading 10 bytes from 0x814e: -110
> 
> This behaviour appears to have been initialing introduced in
> ec6e1b4082d9. This doesn't seem to be based on information in either the
> GT911 or GT9271 datasheets cited as sources of information for this
> change. Thus it seems likely that it is based on functionality in the
> Android driver which it also lists. This behaviour may be viable in very
> specific instances where the hardware is well known, but seems unwise in
> the upstream kernel where such hardware requirements can't be
> guaranteed.
> 
> Remove this over optimisation to improve reliability on non-ACPI
> devices.
> 
> Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
> 
> ---
> 
> Changes since v1:
>  - Dropping gpiod_rst_flags and directly passing GPIOD_ASIS when
>    requesting the reset pin.

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hansg@kernel.org>

Regards,

Hans




> 
>  drivers/input/touchscreen/goodix.c | 27 +--------------------------
>  drivers/input/touchscreen/goodix.h |  1 -
>  2 files changed, 1 insertion(+), 27 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
> index 252dcae039f8..f838f92100c2 100644
> --- a/drivers/input/touchscreen/goodix.c
> +++ b/drivers/input/touchscreen/goodix.c
> @@ -796,17 +796,6 @@ int goodix_reset_no_int_sync(struct goodix_ts_data *ts)
>  
>  	usleep_range(6000, 10000);		/* T4: > 5ms */
>  
> -	/*
> -	 * Put the reset pin back in to input / high-impedance mode to save
> -	 * power. Only do this in the non ACPI case since some ACPI boards
> -	 * don't have a pull-up, so there the reset pin must stay active-high.
> -	 */
> -	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_GPIO) {
> -		error = gpiod_direction_input(ts->gpiod_rst);
> -		if (error)
> -			goto error;
> -	}
> -
>  	return 0;
>  
>  error:
> @@ -957,14 +946,6 @@ static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts)
>  		return -EINVAL;
>  	}
>  
> -	/*
> -	 * Normally we put the reset pin in input / high-impedance mode to save
> -	 * power. But some x86/ACPI boards don't have a pull-up, so for the ACPI
> -	 * case, leave the pin as is. This results in the pin not being touched
> -	 * at all on x86/ACPI boards, except when needed for error-recover.
> -	 */
> -	ts->gpiod_rst_flags = GPIOD_ASIS;
> -
>  	return devm_acpi_dev_add_driver_gpios(dev, gpio_mapping);
>  }
>  #else
> @@ -989,12 +970,6 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)
>  		return -EINVAL;
>  	dev = &ts->client->dev;
>  
> -	/*
> -	 * By default we request the reset pin as input, leaving it in
> -	 * high-impedance when not resetting the controller to save power.
> -	 */
> -	ts->gpiod_rst_flags = GPIOD_IN;
> -
>  	ts->avdd28 = devm_regulator_get(dev, "AVDD28");
>  	if (IS_ERR(ts->avdd28))
>  		return dev_err_probe(dev, PTR_ERR(ts->avdd28), "Failed to get AVDD28 regulator\n");
> @@ -1019,7 +994,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)
>  	ts->gpiod_int = gpiod;
>  
>  	/* Get the reset line GPIO pin number */
> -	gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_RST_NAME, ts->gpiod_rst_flags);
> +	gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_RST_NAME, GPIOD_ASIS);
>  	if (IS_ERR(gpiod))
>  		return dev_err_probe(dev, PTR_ERR(gpiod), "Failed to get %s GPIO\n",
>  				     GOODIX_GPIO_RST_NAME);
> diff --git a/drivers/input/touchscreen/goodix.h b/drivers/input/touchscreen/goodix.h
> index 87797cc88b32..0d1e8a8d2cba 100644
> --- a/drivers/input/touchscreen/goodix.h
> +++ b/drivers/input/touchscreen/goodix.h
> @@ -88,7 +88,6 @@ struct goodix_ts_data {
>  	struct gpio_desc *gpiod_rst;
>  	int gpio_count;
>  	int gpio_int_idx;
> -	enum gpiod_flags gpiod_rst_flags;
>  	char id[GOODIX_ID_MAX_LEN + 1];
>  	char cfg_name[64];
>  	u16 version;


^ permalink raw reply

* Re: [PATCH v3] Input: bcm5974 - Driver cleanup by replacing dprintk with dev_dbg
From: Bhanu Seshu Kumar Valluri @ 2025-10-09 17:34 UTC (permalink / raw)
  To: rydberg, dmitry.torokhov
  Cc: linux-input, skhan, linux-kernel, linux-kernel-mentees,
	bhanuseshukumar
In-Reply-To: <20250903085506.6042-1-bhanuseshukumar@gmail.com>

On 03/09/25 14:25, Bhanu Seshu Kumar Valluri wrote:
> Debug printk messages are converted to dev_dbg based logs
> for better control over debug messages using dynamic logging.
> 
> Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
> ---
>  Changes in V3
>  1. Name in the from tag & signed-off tag are matched.
>  
>  Note: This patch is tested for compilation.
>  v1 patch : https://lore.kernel.org/all/20250902164351.36828-1-bhanuseshukumar@gmail.com/
>  v2 patch : https://lore.kernel.org/all/20250903061908.41910-1-bhanuseshukumar@gmail.com/ 
> 
>  drivers/input/mouse/bcm5974.c | 18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
> index dfdfb59cc8b5..03e112666c2e 100644
> --- a/drivers/input/mouse/bcm5974.c
> +++ b/drivers/input/mouse/bcm5974.c
> @@ -156,13 +156,6 @@ MODULE_AUTHOR("Henrik Rydberg");
>  MODULE_DESCRIPTION("Apple USB BCM5974 multitouch driver");
>  MODULE_LICENSE("GPL");
>  
> -#define dprintk(level, format, a...)\
> -	{ if (debug >= level) printk(KERN_DEBUG format, ##a); }
> -
> -static int debug = 1;
> -module_param(debug, int, 0644);
> -MODULE_PARM_DESC(debug, "Activate debugging output");
> -
>  /* button data structure */
>  struct bt_data {
>  	u8 unknown1;		/* constant */
> @@ -550,8 +543,7 @@ static int report_bt_state(struct bcm5974 *dev, int size)
>  	if (size != sizeof(struct bt_data))
>  		return -EIO;
>  
> -	dprintk(7,
> -		"bcm5974: button data: %x %x %x %x\n",
> +	dev_dbg(&dev->intf->dev, "button data: %x %x %x %x\n",
>  		dev->bt_data->unknown1, dev->bt_data->button,
>  		dev->bt_data->rel_x, dev->bt_data->rel_y);
>  
> @@ -688,7 +680,7 @@ static int bcm5974_wellspring_mode(struct bcm5974 *dev, bool on)
>  		goto out;
>  	}
>  
> -	dprintk(2, "bcm5974: switched to %s mode.\n",
> +	dev_dbg(&dev->intf->dev, "switched to %s mode.\n",
>  		on ? "wellspring" : "normal");
>  
>   out:
> @@ -718,7 +710,7 @@ static void bcm5974_irq_button(struct urb *urb)
>  	}
>  
>  	if (report_bt_state(dev, dev->bt_urb->actual_length))
> -		dprintk(1, "bcm5974: bad button package, length: %d\n",
> +		dev_dbg(&intf->dev, "bad button package, length: %d\n",
>  			dev->bt_urb->actual_length);
>  
>  exit:
> @@ -753,7 +745,7 @@ static void bcm5974_irq_trackpad(struct urb *urb)
>  		goto exit;
>  
>  	if (report_tp_state(dev, dev->tp_urb->actual_length))
> -		dprintk(1, "bcm5974: bad trackpad package, length: %d\n",
> +		dev_dbg(&intf->dev, "bad trackpad package, length: %d\n",
>  			dev->tp_urb->actual_length);
>  
>  exit:
> @@ -786,7 +778,7 @@ static int bcm5974_start_traffic(struct bcm5974 *dev)
>  
>  	error = bcm5974_wellspring_mode(dev, true);
>  	if (error) {
> -		dprintk(1, "bcm5974: mode switch failed\n");
> +		dev_dbg(&dev->intf->dev, "mode switch failed\n");
>  		goto err_out;
>  	}
>  
Hi,

I just wanted to check if you had a chance to review it or if any changes are needed from my side.

Regards,
Bhanu Seshu Kumar Valluri

^ permalink raw reply

* Re: [PATCH RESEND v5 0/7] Input: synaptics-rmi4 - add quirks for third party touchscreen controllers
From: Rob Herring @ 2025-10-09 14:55 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: David Heidelberg, Kaustabh Chakraborty, Krzysztof Kozlowski,
	Conor Dooley, Jason A. Donenfeld, Matthias Schiffer,
	Vincent Huang, linux-input, devicetree, linux-kernel, phone-devel,
	~postmarketos/upstreaming, Casey Connolly, Krzysztof Kozlowski
In-Reply-To: <5gcq5xsurdp24o7wndo2fm7pjsc3khco52ji34jjmeet2nidl4@rkbh4a2c4d3q>

On Sun, Sep 21, 2025 at 11:30:22PM -0700, Dmitry Torokhov wrote:
> Hi David,
> 
> On Tue, Sep 16, 2025 at 11:29:45AM +0200, David Heidelberg wrote:
> > On 07/08/2025 06:29, Dmitry Torokhov wrote:
> > > Hi David,
> > > 
> > > On Thu, Jul 31, 2025 at 11:06:50PM +0200, David Heidelberg via B4 Relay wrote:
> > > > With the growing popularity of running upstream Linux on mobile devices,
> > > > we're beginning to run into more and more edgecases. The OnePlus 6 is a
> > > > fairly well supported 2018 era smartphone, selling over a million units
> > > > in it's first 22 days. With this level of popularity, it's almost
> > > > inevitable that we get third party replacement displays, and as a
> > > > result, replacement touchscreen controllers.
> > > > 
> > > > The OnePlus 6 shipped with an extremely usecase specific touchscreen
> > > > driver, it implemented only the bare minimum parts of the highly generic
> > > > rmi4 protocol, instead hardcoding most of the register addresses.
> > > > 
> > > > As a result, the third party touchscreen controllers that are often
> > > > found in replacement screens, implement only the registers that the
> > > > downstream driver reads from. They additionally have other restrictions
> > > > such as heavy penalties on unaligned reads.
> > > > 
> > > > This series attempts to implement the necessary workaround to support
> > > > some of these chips with the rmi4 driver. Although it's worth noting
> > > > that at the time of writing there are other unofficial controllers in
> > > > the wild that don't work even with these patches.
> > > > 
> > > > We have been shipping these patches in postmarketOS for the last several
> > > > years, and they are known to not cause any regressions on the OnePlus
> > > > 6/6T (with the official Synaptics controller), however I don't own any
> > > > other rmi4 hardware to further validate this.
> > > 
> > > Sorry for not handling the patches in the last few submissions. I am
> > > planning on addressing them once merge window opens.
> > 
> > Hello Dmitry, kind reminder about the patch series as the window is open.
> 
> I was looking at the patch series again and with the exception of patch
> #5 they make little sense for sensors other than ones used in OnePlus 6.
> 
> I wonder if we could key it off of something, maybe a distinct
> compatible or a property? Rob, Krzysztof, any suggestions on how to deal
> with devices that do not properly implement the protocol for which they
> claim compatible?

A compatible is "the way" as David has done. Once again, generic 
compatibles have proven inadequate.

Rob

^ permalink raw reply

* Re: [PATCH v3 04/11] HID: haptic: introduce hid_haptic_device
From: Thorsten Leemhuis @ 2025-10-09 14:43 UTC (permalink / raw)
  To: Jonathan Denose, Jiri Kosina, Benjamin Tissoires, Dmitry Torokhov,
	Jonathan Corbet, Henrik Rydberg
  Cc: linux-input, linux-kernel, linux-doc, Angela Czubak,
	Sean O'Brien
In-Reply-To: <20250818-support-forcepads-v3-4-e4f9ab0add84@google.com>

On 8/19/25 01:08, Jonathan Denose wrote:
> From: Angela Czubak <aczubak@google.com>
> 
> Define a new structure that contains simple haptic device configuration
> as well as current state.
> Add functions that recognize auto trigger and manual trigger reports
> as well as save their addresses.
> Verify that the pressure unit is either grams or newtons.
> Mark the input device as a haptic touchpad if the unit is correct and
> the reports are found.
>  [...]
> +config HID_HAPTIC
> +	tristate "Haptic touchpad support"
> +	default n
> +	help
> +	Support for touchpads with force sensors and haptic actuators instead of a
> +	traditional button.
> +	Adds extra parsing and FF device for the hid multitouch driver.
> +	It can be used for Elan 2703 haptic touchpad.
> +
> +	If unsure, say N.
> +
>  menu "Special HID drivers"

I suspect this change is related to a build error I ran into today:

  MODPOST Module.symvers
ERROR: modpost: "hid_haptic_init" [drivers/hid/hid-multitouch.ko] undefined!
ERROR: modpost: "hid_haptic_pressure_increase" [drivers/hid/hid-multitouch.ko] undefined!
ERROR: modpost: "hid_haptic_check_pressure_unit" [drivers/hid/hid-multitouch.ko] undefined!
ERROR: modpost: "hid_haptic_input_configured" [drivers/hid/hid-multitouch.ko] undefined!
ERROR: modpost: "hid_haptic_input_mapping" [drivers/hid/hid-multitouch.ko] undefined!
ERROR: modpost: "hid_haptic_feature_mapping" [drivers/hid/hid-multitouch.ko] undefined!
ERROR: modpost: "hid_haptic_pressure_reset" [drivers/hid/hid-multitouch.ko] undefined!
make[3]: *** [/home/thl/var/linux.dev/scripts/Makefile.modpost:147: Module.symvers] Error 1

The config where this occurred had this:

CONFIG_HID=y
CONFIG_HID_MULTITOUCH=m
CONFIG_HID_HAPTIC=m

Changing the latter to "CONFIG_HID_HAPTIC=y" fixed the problem for me.

Ciao, Thorsten  
>  config HID_A4TECH
> diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
> index 10ae5dedbd84708d988ea1f594d409ccebd85ebb..361a7daedeb85454114def8afb5f58caeab58a00 100644
> --- a/drivers/hid/Makefile
> +++ b/drivers/hid/Makefile
> @@ -4,6 +4,7 @@
>  #
>  hid-y			:= hid-core.o hid-input.o hid-quirks.o
>  hid-$(CONFIG_DEBUG_FS)		+= hid-debug.o
> +hid-$(CONFIG_HID_HAPTIC)	+= hid-haptic.o
>  
>  obj-$(CONFIG_HID_BPF)		+= bpf/
>  
> diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..d659a430c1a6b06ded31d49efe4bded909671cb6
> --- /dev/null
> +++ b/drivers/hid/hid-haptic.c
> @@ -0,0 +1,72 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + *  HID Haptic support for Linux
> + *
> + *  Copyright (c) 2021 Angela Czubak <acz@semihalf.com>
> + */
> +
> +#include "hid-haptic.h"
> +
> +void hid_haptic_feature_mapping(struct hid_device *hdev,
> +				struct hid_haptic_device *haptic,
> +				struct hid_field *field, struct hid_usage *usage)
> +{
> +	if (usage->hid == HID_HP_AUTOTRIGGER) {
> +		if (usage->usage_index >= field->report_count) {
> +			dev_err(&hdev->dev,
> +				"HID_HP_AUTOTRIGGER out of range\n");
> +			return;
> +		}
> +
> +		hid_device_io_start(hdev);
> +		hid_hw_request(hdev, field->report, HID_REQ_GET_REPORT);
> +		hid_hw_wait(hdev);
> +		hid_device_io_stop(hdev);
> +		haptic->default_auto_trigger =
> +			field->value[usage->usage_index];
> +		haptic->auto_trigger_report = field->report;
> +	}
> +}
> +EXPORT_SYMBOL_GPL(hid_haptic_feature_mapping);
> +
> +bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
> +				    struct hid_input *hi, struct hid_field *field)
> +{
> +	if (field->unit == HID_UNIT_GRAM || field->unit == HID_UNIT_NEWTON)
> +		return true;
> +	return false;
> +}
> +EXPORT_SYMBOL_GPL(hid_haptic_check_pressure_unit);
> +
> +int hid_haptic_input_mapping(struct hid_device *hdev,
> +			     struct hid_haptic_device *haptic,
> +			     struct hid_input *hi,
> +			     struct hid_field *field, struct hid_usage *usage,
> +			     unsigned long **bit, int *max)
> +{
> +	if (usage->hid == HID_HP_MANUALTRIGGER) {
> +		haptic->manual_trigger_report = field->report;
> +		/* we don't really want to map these fields */
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(hid_haptic_input_mapping);
> +
> +int hid_haptic_input_configured(struct hid_device *hdev,
> +				struct hid_haptic_device *haptic,
> +				struct hid_input *hi)
> +{
> +
> +	if (hi->application == HID_DG_TOUCHPAD) {
> +		if (haptic->auto_trigger_report &&
> +		    haptic->manual_trigger_report) {
> +			__set_bit(INPUT_PROP_HAPTIC_TOUCHPAD, hi->input->propbit);
> +			return 1;
> +		}
> +		return 0;
> +	}
> +	return -1;
> +}
> +EXPORT_SYMBOL_GPL(hid_haptic_input_configured);
> diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..2e89addf5ec280d5b9a59d06088cc08bd4f445c1
> --- /dev/null
> +++ b/drivers/hid/hid-haptic.h
> @@ -0,0 +1,101 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + *  HID Haptic support for Linux
> + *
> + *  Copyright (c) 2021 Angela Czubak <acz@semihalf.com>
> + */
> +
> +#include <linux/hid.h>
> +
> +#define HID_HAPTIC_ORDINAL_WAVEFORMNONE 1
> +#define HID_HAPTIC_ORDINAL_WAVEFORMSTOP 2
> +
> +#define HID_HAPTIC_MODE_DEVICE 0
> +#define HID_HAPTIC_MODE_HOST 1
> +
> +struct hid_haptic_effect {
> +	u8 *report_buf;
> +	struct input_dev *input_dev;
> +	struct work_struct work;
> +	struct list_head control;
> +	struct mutex control_mutex;
> +};
> +
> +struct hid_haptic_effect_node {
> +	struct list_head node;
> +	struct file *file;
> +};
> +
> +struct hid_haptic_device {
> +	struct input_dev *input_dev;
> +	struct hid_device *hdev;
> +	struct hid_report *auto_trigger_report;
> +	struct mutex auto_trigger_mutex;
> +	struct workqueue_struct *wq;
> +	struct hid_report *manual_trigger_report;
> +	struct mutex manual_trigger_mutex;
> +	size_t manual_trigger_report_len;
> +	int pressed_state;
> +	s32 pressure_sum;
> +	s32 force_logical_minimum;
> +	s32 force_physical_minimum;
> +	s32 force_resolution;
> +	u32 mode;
> +	u32 default_auto_trigger;
> +	u32 vendor_page;
> +	u32 vendor_id;
> +	u32 max_waveform_id;
> +	u32 max_duration_id;
> +	u16 *hid_usage_map;
> +	u32 *duration_map;
> +	u16 press_ordinal;
> +	u16 release_ordinal;
> +	struct hid_haptic_effect *effect;
> +	struct hid_haptic_effect stop_effect;
> +};
> +
> +#if IS_ENABLED(CONFIG_HID_HAPTIC)
> +void hid_haptic_feature_mapping(struct hid_device *hdev,
> +				struct hid_haptic_device *haptic,
> +				struct hid_field *field, struct hid_usage
> +				*usage);
> +bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
> +				    struct hid_input *hi, struct hid_field *field);
> +int hid_haptic_input_mapping(struct hid_device *hdev,
> +			     struct hid_haptic_device *haptic,
> +			     struct hid_input *hi,
> +			     struct hid_field *field, struct hid_usage *usage,
> +			     unsigned long **bit, int *max);
> +int hid_haptic_input_configured(struct hid_device *hdev,
> +				struct hid_haptic_device *haptic,
> +				struct hid_input *hi);
> +#else
> +static inline
> +void hid_haptic_feature_mapping(struct hid_device *hdev,
> +				struct hid_haptic_device *haptic,
> +				struct hid_field *field, struct hid_usage
> +				*usage)
> +{}
> +static inline
> +bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
> +				    struct hid_input *hi, struct hid_field *field)
> +{
> +	return false;
> +}
> +static inline
> +int hid_haptic_input_mapping(struct hid_device *hdev,
> +			     struct hid_haptic_device *haptic,
> +			     struct hid_input *hi,
> +			     struct hid_field *field, struct hid_usage *usage,
> +			     unsigned long **bit, int *max)
> +{
> +	return 0;
> +}
> +static inline
> +int hid_haptic_input_configured(struct hid_device *hdev,
> +				struct hid_haptic_device *haptic,
> +				struct hid_input *hi)
> +{
> +	return 0;
> +}
> +#endif
> 


^ permalink raw reply

* [PATCH v2] input: goodix: Remove setting of RST pin to input
From: Martyn Welch @ 2025-10-09 13:41 UTC (permalink / raw)
  To: Hans de Goede, Dmitry Torokhov
  Cc: kernel, Martyn Welch, linux-input, linux-kernel

The reset line is being set to input on non-ACPI devices apparently to
save power. This isn't being done on ACPI devices as it's been found
that some ACPI devices don't have a pull-up resistor fitted. This can
also be the case for non-ACPI devices, resulting in:

[  941.672207] Goodix-TS 1-0014: Error reading 10 bytes from 0x814e: -110
[  942.696168] Goodix-TS 1-0014: Error reading 10 bytes from 0x814e: -110
[  945.832208] Goodix-TS 1-0014: Error reading 10 bytes from 0x814e: -110

This behaviour appears to have been initialing introduced in
ec6e1b4082d9. This doesn't seem to be based on information in either the
GT911 or GT9271 datasheets cited as sources of information for this
change. Thus it seems likely that it is based on functionality in the
Android driver which it also lists. This behaviour may be viable in very
specific instances where the hardware is well known, but seems unwise in
the upstream kernel where such hardware requirements can't be
guaranteed.

Remove this over optimisation to improve reliability on non-ACPI
devices.

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>

---

Changes since v1:
 - Dropping gpiod_rst_flags and directly passing GPIOD_ASIS when
   requesting the reset pin.

 drivers/input/touchscreen/goodix.c | 27 +--------------------------
 drivers/input/touchscreen/goodix.h |  1 -
 2 files changed, 1 insertion(+), 27 deletions(-)

diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index 252dcae039f8..f838f92100c2 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -796,17 +796,6 @@ int goodix_reset_no_int_sync(struct goodix_ts_data *ts)
 
 	usleep_range(6000, 10000);		/* T4: > 5ms */
 
-	/*
-	 * Put the reset pin back in to input / high-impedance mode to save
-	 * power. Only do this in the non ACPI case since some ACPI boards
-	 * don't have a pull-up, so there the reset pin must stay active-high.
-	 */
-	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_GPIO) {
-		error = gpiod_direction_input(ts->gpiod_rst);
-		if (error)
-			goto error;
-	}
-
 	return 0;
 
 error:
@@ -957,14 +946,6 @@ static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts)
 		return -EINVAL;
 	}
 
-	/*
-	 * Normally we put the reset pin in input / high-impedance mode to save
-	 * power. But some x86/ACPI boards don't have a pull-up, so for the ACPI
-	 * case, leave the pin as is. This results in the pin not being touched
-	 * at all on x86/ACPI boards, except when needed for error-recover.
-	 */
-	ts->gpiod_rst_flags = GPIOD_ASIS;
-
 	return devm_acpi_dev_add_driver_gpios(dev, gpio_mapping);
 }
 #else
@@ -989,12 +970,6 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)
 		return -EINVAL;
 	dev = &ts->client->dev;
 
-	/*
-	 * By default we request the reset pin as input, leaving it in
-	 * high-impedance when not resetting the controller to save power.
-	 */
-	ts->gpiod_rst_flags = GPIOD_IN;
-
 	ts->avdd28 = devm_regulator_get(dev, "AVDD28");
 	if (IS_ERR(ts->avdd28))
 		return dev_err_probe(dev, PTR_ERR(ts->avdd28), "Failed to get AVDD28 regulator\n");
@@ -1019,7 +994,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)
 	ts->gpiod_int = gpiod;
 
 	/* Get the reset line GPIO pin number */
-	gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_RST_NAME, ts->gpiod_rst_flags);
+	gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_RST_NAME, GPIOD_ASIS);
 	if (IS_ERR(gpiod))
 		return dev_err_probe(dev, PTR_ERR(gpiod), "Failed to get %s GPIO\n",
 				     GOODIX_GPIO_RST_NAME);
diff --git a/drivers/input/touchscreen/goodix.h b/drivers/input/touchscreen/goodix.h
index 87797cc88b32..0d1e8a8d2cba 100644
--- a/drivers/input/touchscreen/goodix.h
+++ b/drivers/input/touchscreen/goodix.h
@@ -88,7 +88,6 @@ struct goodix_ts_data {
 	struct gpio_desc *gpiod_rst;
 	int gpio_count;
 	int gpio_int_idx;
-	enum gpiod_flags gpiod_rst_flags;
 	char id[GOODIX_ID_MAX_LEN + 1];
 	char cfg_name[64];
 	u16 version;
-- 
2.39.5


^ permalink raw reply related

* Re: [PATCH v12 0/6] add support for pf1550 PMIC MFD-based drivers
From: Lee Jones @ 2025-10-09 12:51 UTC (permalink / raw)
  To: samuel.kayode
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Liam Girdwood,
	Mark Brown, Dmitry Torokhov, Sebastian Reichel, Frank Li, imx,
	devicetree, linux-kernel, linux-input, linux-pm, Abel Vesa,
	Abel Vesa, Robin Gong, Robin Gong, Enric Balletbo i Serra,
	Sean Nyekjaer, Christophe JAILLET, Krzysztof Kozlowski,
	Sebastian Reichel
In-Reply-To: <20251001-pf1550-v12-0-a3302aa41687@savoirfairelinux.com>

On Wed, 01 Oct 2025, Samuel Kayode via B4 Relay wrote:

> This series adds support for pf1550 PMIC. It provides the core driver and
> sub-drivers for the regulator, power supply and input subsystems.

Note to self: Everything is in order.  Apply to an IB once -rc1 is out.

-- 
Lee Jones [李琼斯]

^ permalink raw reply

* Re: (subset) [PATCH v2 00/16] Align availability checks on fwnode child node enumeration
From: Lee Jones @ 2025-10-09 12:38 UTC (permalink / raw)
  To: linux-acpi, Sakari Ailus
  Cc: linux-kernel, linux-input, linux-leds, linux-media, netdev,
	linux-spi, Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Javier Carrasco, Dmitry Torokhov, Lee Jones, Pavel Machek,
	Matthias Fend, Chanwoo Choi, Krzysztof Kozlowski,
	Laurent Pinchart, Paul Elder, Mauro Carvalho Chehab,
	Horatiu Vultur, UNGLinuxDriver, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Mark Brown,
	Thomas Gleixner, Ingo Molnar, Jonathan Cameron
In-Reply-To: <20250924074602.266292-1-sakari.ailus@linux.intel.com>

On Wed, 24 Sep 2025 10:45:46 +0300, Sakari Ailus wrote:
> Historically the fwnode property API has enumerated only available device
> nodes on OF whereas on ACPI, also nodes that haven't been present in the
> system have been provided. Both OF and ACPI have similar concepts of node
> availbility, on OF it's the "status" property present on device nodes and
> on ACPI the _STA object evaluates to device present, enabled and
> functional bits, of which the present and functional bits are currently
> being used to determine whether to enumerate a device.
> 
> [...]

Applied, thanks!

[13/16] leds: Use fwnode_for_each_child_node() instead
        commit: 34dbf5b458193b120a4a00777f2045f40c3db974
[14/16] leds: Use fwnode_get_next_child_node() instead
        commit: 93ecfb549059e3c77da16364c0f6fbddb42b147b

--
Lee Jones [李琼斯]


^ permalink raw reply

* Re: [PATCH] HID: i2c-hid: patch Lenovo Yoga Slim 7x Keyboard rdesc
From: Benjamin Tissoires @ 2025-10-09  8:29 UTC (permalink / raw)
  To: Lauri Tirkkonen; +Cc: Jiri Kosina, linux-input, linux-kernel
In-Reply-To: <aOdsqHznz1SJdadC@mail.hacktheplanet.fi>

On Oct 09 2025, Lauri Tirkkonen wrote:
> Hi Benjamin,
> 
> On Thu, Oct 09 2025 09:38:50 +0200, Benjamin Tissoires wrote:
> > > diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
> > > index 63f46a2e5788..d78bd97ec24e 100644
> > > --- a/drivers/hid/i2c-hid/i2c-hid-core.c
> > > +++ b/drivers/hid/i2c-hid/i2c-hid-core.c
> > 
> > Why patching i2c-hid-core when this is clearly a logical bug, not a
> > transport (I2C) bug?
> > 
> > I would rather see this fixup in hid-lenovo.c along with the other
> > lenovo fixes.
> 
> I'm not exactly familiar with HID; please bear with me :) If
> i2c-hid-core is not the correct place for this kind of thing, I can move
> it, but I'm going to need some guidance on where the correct place is.
> 
> This device uses hid-over-i2c, not hid-lenovo; I've got
> CONFIG_HID_LENOVO=m but the module is not even loaded. I don't see how
> putting the fixup in a module that does not attach to the device could
> work. So where should it go?

Well, the transport layer is i2c-hid, but the logical implementation is
in hid-generic which leverages the hid core default implementation.

In your case, you need to tell hid-lenovo to handle the device so we
stick to nice and tidy approach with each HID driver handling it's own
business.

Adding a line like the following will bind the keyboard part of the
device to hid-lenovo in lenovo_devices[]:
	{ HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
		     USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_YOGA_SLIM_7X) },

If you don't use hid-multitouch on the same device you need a
HID_I2C_DEVICE() macro instead.

Once this is in, hid-lenovo.ko will bind to the device, and then we can
start fixing the report descriptor.

> 
> 	[  796.926931] input: hid-over-i2c 048D:8987 Keyboard as /devices/platform/soc@0/bc0000.geniqup/b80000.i2c/i2c-1/1-003a/0018:048D:8987.000F/input/input36
> 
> As a side note: apparently there is at least one other device in
> existence with a similar error in the report descriptor, which works
> fine on Windows:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=652f3d00de523a17b0cebe7b90debccf13aa8c31

Well, Windows is known for horrible hacks in their own generic layer,
but trying to mimmic them is sometimes harder than it looks :(
Especially because we also handle non Windows devices, and we might
break them while mimmicing Windows while our HID implementation is
currently rather "clean".

Cheers,
Benjamin

> 
> -- 
> Lauri Tirkkonen | lotheac @ IRCnet

^ permalink raw reply

* Re: [PATCH] HID: i2c-hid: patch Lenovo Yoga Slim 7x Keyboard rdesc
From: Lauri Tirkkonen @ 2025-10-09  8:04 UTC (permalink / raw)
  To: Benjamin Tissoires; +Cc: Jiri Kosina, linux-input, linux-kernel
In-Reply-To: <lxtbtu5frygbw7qzfaelc63vgientm7d6oo7dt6jeassl3ttbh@f22h223wehbm>

Hi Benjamin,

On Thu, Oct 09 2025 09:38:50 +0200, Benjamin Tissoires wrote:
> > diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
> > index 63f46a2e5788..d78bd97ec24e 100644
> > --- a/drivers/hid/i2c-hid/i2c-hid-core.c
> > +++ b/drivers/hid/i2c-hid/i2c-hid-core.c
> 
> Why patching i2c-hid-core when this is clearly a logical bug, not a
> transport (I2C) bug?
> 
> I would rather see this fixup in hid-lenovo.c along with the other
> lenovo fixes.

I'm not exactly familiar with HID; please bear with me :) If
i2c-hid-core is not the correct place for this kind of thing, I can move
it, but I'm going to need some guidance on where the correct place is.

This device uses hid-over-i2c, not hid-lenovo; I've got
CONFIG_HID_LENOVO=m but the module is not even loaded. I don't see how
putting the fixup in a module that does not attach to the device could
work. So where should it go?

	[  796.926931] input: hid-over-i2c 048D:8987 Keyboard as /devices/platform/soc@0/bc0000.geniqup/b80000.i2c/i2c-1/1-003a/0018:048D:8987.000F/input/input36

As a side note: apparently there is at least one other device in
existence with a similar error in the report descriptor, which works
fine on Windows:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=652f3d00de523a17b0cebe7b90debccf13aa8c31

-- 
Lauri Tirkkonen | lotheac @ IRCnet

^ permalink raw reply

* Re: [PATCH] HID: i2c-hid: patch Lenovo Yoga Slim 7x Keyboard rdesc
From: Benjamin Tissoires @ 2025-10-09  7:38 UTC (permalink / raw)
  To: Lauri Tirkkonen; +Cc: Jiri Kosina, linux-input, linux-kernel
In-Reply-To: <aOdLxAEYQpV2zp77@mail.hacktheplanet.fi>

On Oct 09 2025, Lauri Tirkkonen wrote:
> The keyboard of this device has the following in its report description
> for Usage (Keyboard) in Collection (Application):
> 
> 	# 0x15, 0x00,                    //  Logical Minimum (0)                52
> 	# 0x25, 0x65,                    //  Logical Maximum (101)              54
> 	# 0x05, 0x07,                    //  Usage Page (Keyboard)              56
> 	# 0x19, 0x00,                    //  Usage Minimum (0)                  58
> 	# 0x29, 0xdd,                    //  Usage Maximum (221)                60
> 	# 0x81, 0x00,                    //  Input (Data,Arr,Abs)               62
> 
> Since the Usage Min/Max range exceeds the Logical Min/Max range,
> keypresses outside the Logical range are not recognized. This includes,
> for example, the Japanese language keyboard variant's keys for |, _ and
> \.
> 
> Patch the report description to make the Logical range match the Usage
> range, fixing the interpretation of keypresses above 101 on this device.
> 
> Signed-off-by: Lauri Tirkkonen <lauri@hacktheplanet.fi>
> ---
>  drivers/hid/hid-ids.h              |  1 +
>  drivers/hid/i2c-hid/i2c-hid-core.c | 25 +++++++++++++++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> index 5721b8414bbd..bbb932145d2c 100644
> --- a/drivers/hid/hid-ids.h
> +++ b/drivers/hid/hid-ids.h
> @@ -715,6 +715,7 @@
>  #define USB_DEVICE_ID_ITE_LENOVO_YOGA2  0x8350
>  #define I2C_DEVICE_ID_ITE_LENOVO_LEGION_Y720	0x837a
>  #define USB_DEVICE_ID_ITE_LENOVO_YOGA900	0x8396
> +#define I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X	0x8987
>  #define USB_DEVICE_ID_ITE8595		0x8595
>  #define USB_DEVICE_ID_ITE_MEDION_E1239T	0xce50
>  
> diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
> index 63f46a2e5788..d78bd97ec24e 100644
> --- a/drivers/hid/i2c-hid/i2c-hid-core.c
> +++ b/drivers/hid/i2c-hid/i2c-hid-core.c

Why patching i2c-hid-core when this is clearly a logical bug, not a
transport (I2C) bug?

I would rather see this fixup in hid-lenovo.c along with the other
lenovo fixes.

Cheers,
Benjamin

> @@ -740,6 +740,26 @@ static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum,
>  	}
>  }
>  
> +static void patch_lenovo_yoga_slim7x_keyboard_rdesc(struct i2c_hid *ihid,
> +						    char *rdesc,
> +						    unsigned int rsize)
> +{
> +	if (!(rsize == 0xb0 &&
> +	      rdesc[0x34] == 0x15 && rdesc[0x35] == 0x00 && // Logical Minimum (0)
> +	      rdesc[0x36] == 0x25 && rdesc[0x37] == 0x65 && // Logical Maximum (101)
> +	      rdesc[0x38] == 0x05 && rdesc[0x39] == 0x07 && // Usage Page (Keyboard)
> +	      rdesc[0x3a] == 0x19 && rdesc[0x3b] == 0x00 && // Usage Minimum (0)
> +	      rdesc[0x3c] == 0x29 && rdesc[0x3d] == 0xdd))  // Usage Maximum (221)
> +		return;
> +
> +	u8 logical_max = rdesc[0x37];
> +	u8 usage_max = rdesc[0x3d];
> +
> +	rdesc[0x37] = usage_max;
> +	i2c_hid_dbg(ihid, "%s: patched logical max from %u to %u\n", __func__,
> +			logical_max, usage_max);
> +}
> +
>  static int i2c_hid_parse(struct hid_device *hid)
>  {
>  	struct i2c_client *client = hid->driver_data;
> @@ -793,6 +813,11 @@ static int i2c_hid_parse(struct hid_device *hid)
>  		}
>  	}
>  
> +	if (ihid->hid->vendor == USB_VENDOR_ID_ITE &&
> +	    ihid->hid->product == I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X) {
> +		patch_lenovo_yoga_slim7x_keyboard_rdesc(ihid, rdesc, rsize);
> +	}
> +
>  	i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
>  
>  	ret = hid_parse_report(hid, rdesc, rsize);
> -- 
> 2.51.0
> 
> -- 
> Lauri Tirkkonen | lotheac @ IRCnet

^ permalink raw reply

* [PATCH] HID: i2c-hid: patch Lenovo Yoga Slim 7x Keyboard rdesc
From: Lauri Tirkkonen @ 2025-10-09  5:44 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

The keyboard of this device has the following in its report description
for Usage (Keyboard) in Collection (Application):

	# 0x15, 0x00,                    //  Logical Minimum (0)                52
	# 0x25, 0x65,                    //  Logical Maximum (101)              54
	# 0x05, 0x07,                    //  Usage Page (Keyboard)              56
	# 0x19, 0x00,                    //  Usage Minimum (0)                  58
	# 0x29, 0xdd,                    //  Usage Maximum (221)                60
	# 0x81, 0x00,                    //  Input (Data,Arr,Abs)               62

Since the Usage Min/Max range exceeds the Logical Min/Max range,
keypresses outside the Logical range are not recognized. This includes,
for example, the Japanese language keyboard variant's keys for |, _ and
\.

Patch the report description to make the Logical range match the Usage
range, fixing the interpretation of keypresses above 101 on this device.

Signed-off-by: Lauri Tirkkonen <lauri@hacktheplanet.fi>
---
 drivers/hid/hid-ids.h              |  1 +
 drivers/hid/i2c-hid/i2c-hid-core.c | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5721b8414bbd..bbb932145d2c 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -715,6 +715,7 @@
 #define USB_DEVICE_ID_ITE_LENOVO_YOGA2  0x8350
 #define I2C_DEVICE_ID_ITE_LENOVO_LEGION_Y720	0x837a
 #define USB_DEVICE_ID_ITE_LENOVO_YOGA900	0x8396
+#define I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X	0x8987
 #define USB_DEVICE_ID_ITE8595		0x8595
 #define USB_DEVICE_ID_ITE_MEDION_E1239T	0xce50
 
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 63f46a2e5788..d78bd97ec24e 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -740,6 +740,26 @@ static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum,
 	}
 }
 
+static void patch_lenovo_yoga_slim7x_keyboard_rdesc(struct i2c_hid *ihid,
+						    char *rdesc,
+						    unsigned int rsize)
+{
+	if (!(rsize == 0xb0 &&
+	      rdesc[0x34] == 0x15 && rdesc[0x35] == 0x00 && // Logical Minimum (0)
+	      rdesc[0x36] == 0x25 && rdesc[0x37] == 0x65 && // Logical Maximum (101)
+	      rdesc[0x38] == 0x05 && rdesc[0x39] == 0x07 && // Usage Page (Keyboard)
+	      rdesc[0x3a] == 0x19 && rdesc[0x3b] == 0x00 && // Usage Minimum (0)
+	      rdesc[0x3c] == 0x29 && rdesc[0x3d] == 0xdd))  // Usage Maximum (221)
+		return;
+
+	u8 logical_max = rdesc[0x37];
+	u8 usage_max = rdesc[0x3d];
+
+	rdesc[0x37] = usage_max;
+	i2c_hid_dbg(ihid, "%s: patched logical max from %u to %u\n", __func__,
+			logical_max, usage_max);
+}
+
 static int i2c_hid_parse(struct hid_device *hid)
 {
 	struct i2c_client *client = hid->driver_data;
@@ -793,6 +813,11 @@ static int i2c_hid_parse(struct hid_device *hid)
 		}
 	}
 
+	if (ihid->hid->vendor == USB_VENDOR_ID_ITE &&
+	    ihid->hid->product == I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X) {
+		patch_lenovo_yoga_slim7x_keyboard_rdesc(ihid, rdesc, rsize);
+	}
+
 	i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
 
 	ret = hid_parse_report(hid, rdesc, rsize);
-- 
2.51.0

-- 
Lauri Tirkkonen | lotheac @ IRCnet

^ permalink raw reply related

* Re: [BUG] Side buttons not detected on Telink 2.4G mouse (ID 320f:226f)
From: Linux Hid @ 2025-10-09  3:31 UTC (permalink / raw)
  To: Артем Бігдаш,
	linux-input
In-Reply-To: <CADYkRmrfhRf6VmQjc+su+mepyv=TsHc+aMcL6ryRZ5HTZ8pyFg@mail.gmail.com>

Hello Btema2,

The problem is probably in the report descriptor from the Telink 2.4G 
Wireless Receiver.

Can you send the Configuration, Device, and Report Descriptors from that 
device?

The VID 0x320f belongs to Evision Semiconductor Technology and there is 
already a driver in the kernel (drivers/hid/hid-evision.c). It would be 
easy enough to add a report fixup hook to that driver.

Would you be able to test the patch?

Thanks,
Terry

On 10/5/2025 10:57 AM, Артем Бігдаш wrote:
> Hello,
> 
> I am reporting an issue with a wireless mouse that uses a Telink 2.4G
> receiver. The side buttons (Forward/Back) are not detected by the
> system.
> 
> Device Information:
> - Name: Redragon King Lite
> - lsusb ID: 320f:226f Telink 2.4G Wireless Receiver
> - System: Fedora 42, KDE Plasma
> 
> Diagnostics:
> - Standard tools like `evtest` and `libinput debug-events` show no
> events when the side buttons are pressed. The kernel does not seem to
> create any evdev events for them.
> - However, `hid-recorder` on the correct hidraw interface
> (`/dev/hidraw1`) successfully captures the raw HID reports.
> 
> Raw HID Reports:
> 
> Pressing the first side button (likely Back/Forward) sends this report:
> E: ... 8 01 10 00 00 00 00 00 00
> Releasing it sends:
> E: ... 8 01 00 00 00 00 00 00 00
> 
> Pressing the second side button (likely Forward/Back) sends this report:
> E: ... 8 01 08 00 00 00 00 00 00
> Releasing it sends:
> E: ... 8 01 00 00 00 00 00 00 00
> 
> It seems the `usbhid` driver does not correctly parse these HID
> reports (report ID 1, second byte mask 0x10 and 0x08) into standard
> KEY_BACK/KEY_FORWARD events.
> 
> Could you please advise if a quirk can be added to the kernel to
> support this device correctly? All the necessary diagnostic data
> appears to be above.
> 
> Thank you for your time and work on the Linux kernel.
> 
> Best regards,
> Btema2
> 

^ permalink raw reply

* [PATCH] HID: intel-thc-hid: intel-quicki2c: Fix wrong type casting
From: Xinpeng Sun @ 2025-10-09  3:31 UTC (permalink / raw)
  To: jikos, bentiss
  Cc: srinivas.pandruvada, even.xu, linux-input, linux-kernel,
	Xinpeng Sun, kernel test robot

The type definition of qcdev->i2c_max_frame_size is already
u32, so remove the unnecessary type casting le16_to_cpu.

Signed-off-by: Xinpeng Sun <xinpeng.sun@intel.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202509280841.pxmgBzKW-lkp@intel.com/
---
 drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
index 8433a991e7f4..0156ab391778 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
@@ -466,7 +466,7 @@ static void quicki2c_dma_adv_enable(struct quicki2c_device *qcdev)
 			dev_warn(qcdev->dev,
 				 "Max frame size is smaller than hid max input length!");
 			thc_i2c_set_rx_max_size(qcdev->thc_hw,
-						le16_to_cpu(qcdev->i2c_max_frame_size));
+						qcdev->i2c_max_frame_size);
 		}
 		thc_i2c_rx_max_size_enable(qcdev->thc_hw, true);
 	}
-- 
2.40.1


^ permalink raw reply related

* Re: [PATCH v3 06/13] hwmon: Add Apple Silicon SMC hwmon driver
From: Guenter Roeck @ 2025-10-09  1:58 UTC (permalink / raw)
  To: James Calligeros, Sven Peter, Janne Grunau, Alyssa Rosenzweig,
	Neal Gompa, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Alexandre Belloni, Jean Delvare, Dmitry Torokhov,
	Jonathan Corbet
  Cc: asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc,
	linux-hwmon, linux-input, linux-doc
In-Reply-To: <20251007-macsmc-subdevs-v3-6-d7d3bfd7ae02@gmail.com>

On 10/7/25 04:16, James Calligeros wrote:
> The System Management Controller on Apple Silicon devices is responsible
> for integrating and exposing the data reported by the vast array of
> hardware monitoring sensors present on these devices. It is also
> responsible for fan control, and allows users to manually set fan
> speeds if they so desire. Add a hwmon driver to expose current,
> power, temperature, and voltage monitoring sensors, as well as
> fan speed monitoring and control via the SMC on Apple Silicon devices.
> 
> The SMC firmware has no consistency between devices, even when they
> share an SoC. The FourCC keys used to access sensors are almost
> random. An M1 Mac mini will have different FourCCs for its CPU core
> temperature sensors to an M1 MacBook Pro, for example. For this
> reason, the valid sensors for a given device are specified in a
> child of the SMC Devicetree node. The driver uses this information
> to determine which sensors to make available at runtime.
> 
> Reviewed-by: Neal Gompa <neal@gompa.dev>
> Co-developed-by: Janne Grunau <j@jannau.net>
> Signed-off-by: Janne Grunau <j@jannau.net>
> Signed-off-by: James Calligeros <jcalligeros99@gmail.com>

Acked-by: Guenter Roeck <linux@roeck-us.net>

^ permalink raw reply

* Re: [PATCH v3 02/13] dt-bindings: hwmon: Add Apple System Management Controller hwmon schema
From: Rob Herring (Arm) @ 2025-10-09  0:43 UTC (permalink / raw)
  To: James Calligeros
  Cc: linux-input, Dmitry Torokhov, linux-rtc, asahi, linux-kernel,
	Jonathan Corbet, linux-doc, Alexandre Belloni, devicetree,
	linux-hwmon, Alyssa Rosenzweig, Janne Grunau, Lee Jones,
	Jean Delvare, linux-arm-kernel, Conor Dooley, Guenter Roeck,
	Neal Gompa, Krzysztof Kozlowski, Sven Peter
In-Reply-To: <20251007-macsmc-subdevs-v3-2-d7d3bfd7ae02@gmail.com>


On Tue, 07 Oct 2025 21:16:43 +1000, James Calligeros wrote:
> Apple Silicon devices integrate a vast array of sensors, monitoring
> current, power, temperature, and voltage across almost every part of
> the system. The sensors themselves are all connected to the System
> Management Controller (SMC). The SMC firmware exposes the data
> reported by these sensors via its standard FourCC-based key-value
> API. The SMC is also responsible for monitoring and controlling any
> fans connected to the system, exposing them in the same way.
> 
> For reasons known only to Apple, each device exposes its sensors with
> an almost totally unique set of keys. This is true even for devices
> which share an SoC. An M1 Mac mini, for example, will report its core
> temperatures on different keys to an M1 MacBook Pro. Worse still, the
> SMC does not provide a way to enumerate the available keys at runtime,
> nor do the keys follow any sort of reasonable or consistent naming
> rules that could be used to deduce their purpose. We must therefore
> know which keys are present on any given device, and which function
> they serve, ahead of time.
> 
> Add a schema so that we can describe the available sensors for a given
> Apple Silicon device in the Devicetree.
> 
> Reviewed-by: Neal Gompa <neal@gompa.dev>
> Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
> ---
>  .../bindings/hwmon/apple,smc-hwmon.yaml  | 86 +++++++++++++++++++++++++
>  .../bindings/mfd/apple,smc.yaml          | 36 +++++++++++
>  MAINTAINERS                              |  1 +
>  3 files changed, 123 insertions(+)
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


^ permalink raw reply

* Re: [PATCH v3 1/2] dt-bindings: touchscreen: rename maxim,max11801.yaml to trivial-touch.yaml
From: Rob Herring (Arm) @ 2025-10-08 20:02 UTC (permalink / raw)
  To: Frank Li
  Cc: devicetree, imx, Krzysztof Kozlowski, Conor Dooley,
	Dmitry Torokhov, linux-kernel, linux-input
In-Reply-To: <20251002164413.1112136-1-Frank.Li@nxp.com>


On Thu, 02 Oct 2025 12:44:04 -0400, Frank Li wrote:
> Rename maxim,max11801.yaml to trivial-touch.yaml for simple i2c touch
> controller with one interrupt and common touch properties.
> 
> Add optional reset-gpios and wakeup-source properties.
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> change in v3
> - add wakeup-source and reset-gpios optional properties
> 
> change in v2
> new patch
> 
> previous discussion
> https://lore.kernel.org/imx/20250925-swimming-overspend-ddf7ab4a252c@spud/T/#t
> ---
>  .../{maxim,max11801.yaml => trivial-touch.yaml}     | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>  rename Documentation/devicetree/bindings/input/touchscreen/{maxim,max11801.yaml => trivial-touch.yaml} (70%)
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


^ permalink raw reply

* Re: [git pull] Input updates for v6.18-rc0
From: pr-tracker-bot @ 2025-10-08 18:48 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Linus Torvalds, linux-kernel, linux-input
In-Reply-To: <es25pm67cujd4ufo3uqba5ca3do4mkcw4cdrcdzghrs3tc6azn@d6aejmsh4ywf>

The pull request you sent on Tue, 7 Oct 2025 22:23:34 -0700:

> git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git tags/input-for-v6.18-rc0

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/99cedb6b8f4101e2780f10b9e76d2f346a1e4316

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html

^ permalink raw reply

* [PATCH v3 19/19 5.15.y] minmax.h: remove some #defines that are only expanded once
From: Eliav Farber @ 2025-10-08 15:29 UTC (permalink / raw)
  To: gregkh, jdike, richard, anton.ivanov, dave.hansen, luto, peterz,
	tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, james.morse,
	rric, airlied, daniel, maarten.lankhorst, mripard, tzimmermann,
	robdclark, sean, jdelvare, linux, linus.walleij, dmitry.torokhov,
	maz, wens, jernej.skrabec, agk, snitzer, dm-devel, davem, kuba,
	mcoquelin.stm32, krzysztof.kozlowski, malattia, hdegoede, mgross,
	jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, jack,
	tytso, adilger.kernel, dushistov, luc.vanoostenryck, rostedt,
	pmladek, senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
	akpm, yoshfuji, dsahern, pablo, kadlec, fw, jmaloy, ying.xue,
	shuah, willy, farbere, sashal, quic_akhilpo, ruanjinjie,
	David.Laight, herve.codina, linux-arm-kernel, linux-kernel,
	linux-um, linux-edac, amd-gfx, dri-devel, linux-arm-msm,
	freedreno, linux-hwmon, linux-input, linux-sunxi, linux-media,
	netdev, linux-stm32, platform-driver-x86, linux-scsi,
	linux-staging, linux-btrfs, linux-ext4, linux-sparse, linux-mm,
	netfilter-devel, coreteam, tipc-discussion, linux-kselftest,
	stable
  Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter,
	Jason A. Donenfeld, Jens Axboe, Lorenzo Stoakes, Mateusz Guzik,
	Pedro Falcato
In-Reply-To: <20251008152946.29285-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 v3 18/19 5.15.y] minmax.h: simplify the variants of clamp()
From: Eliav Farber @ 2025-10-08 15:29 UTC (permalink / raw)
  To: gregkh, jdike, richard, anton.ivanov, dave.hansen, luto, peterz,
	tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, james.morse,
	rric, airlied, daniel, maarten.lankhorst, mripard, tzimmermann,
	robdclark, sean, jdelvare, linux, linus.walleij, dmitry.torokhov,
	maz, wens, jernej.skrabec, agk, snitzer, dm-devel, davem, kuba,
	mcoquelin.stm32, krzysztof.kozlowski, malattia, hdegoede, mgross,
	jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, jack,
	tytso, adilger.kernel, dushistov, luc.vanoostenryck, rostedt,
	pmladek, senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
	akpm, yoshfuji, dsahern, pablo, kadlec, fw, jmaloy, ying.xue,
	shuah, willy, farbere, sashal, quic_akhilpo, ruanjinjie,
	David.Laight, herve.codina, linux-arm-kernel, linux-kernel,
	linux-um, linux-edac, amd-gfx, dri-devel, linux-arm-msm,
	freedreno, linux-hwmon, linux-input, linux-sunxi, linux-media,
	netdev, linux-stm32, platform-driver-x86, linux-scsi,
	linux-staging, linux-btrfs, linux-ext4, linux-sparse, linux-mm,
	netfilter-devel, coreteam, tipc-discussion, linux-kselftest,
	stable
  Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter,
	Jason A. Donenfeld, Jens Axboe, Lorenzo Stoakes, Mateusz Guzik,
	Pedro Falcato
In-Reply-To: <20251008152946.29285-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 v3 17/19 5.15.y] minmax.h: move all the clamp() definitions after the min/max() ones
From: Eliav Farber @ 2025-10-08 15:29 UTC (permalink / raw)
  To: gregkh, jdike, richard, anton.ivanov, dave.hansen, luto, peterz,
	tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, james.morse,
	rric, airlied, daniel, maarten.lankhorst, mripard, tzimmermann,
	robdclark, sean, jdelvare, linux, linus.walleij, dmitry.torokhov,
	maz, wens, jernej.skrabec, agk, snitzer, dm-devel, davem, kuba,
	mcoquelin.stm32, krzysztof.kozlowski, malattia, hdegoede, mgross,
	jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, jack,
	tytso, adilger.kernel, dushistov, luc.vanoostenryck, rostedt,
	pmladek, senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
	akpm, yoshfuji, dsahern, pablo, kadlec, fw, jmaloy, ying.xue,
	shuah, willy, farbere, sashal, quic_akhilpo, ruanjinjie,
	David.Laight, herve.codina, linux-arm-kernel, linux-kernel,
	linux-um, linux-edac, amd-gfx, dri-devel, linux-arm-msm,
	freedreno, linux-hwmon, linux-input, linux-sunxi, linux-media,
	netdev, linux-stm32, platform-driver-x86, linux-scsi,
	linux-staging, linux-btrfs, linux-ext4, linux-sparse, linux-mm,
	netfilter-devel, coreteam, tipc-discussion, linux-kselftest,
	stable
  Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter,
	Jason A. Donenfeld, Jens Axboe, Lorenzo Stoakes, Mateusz Guzik,
	Pedro Falcato
In-Reply-To: <20251008152946.29285-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 v3 16/19 5.15.y] minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp()
From: Eliav Farber @ 2025-10-08 15:29 UTC (permalink / raw)
  To: gregkh, jdike, richard, anton.ivanov, dave.hansen, luto, peterz,
	tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, james.morse,
	rric, airlied, daniel, maarten.lankhorst, mripard, tzimmermann,
	robdclark, sean, jdelvare, linux, linus.walleij, dmitry.torokhov,
	maz, wens, jernej.skrabec, agk, snitzer, dm-devel, davem, kuba,
	mcoquelin.stm32, krzysztof.kozlowski, malattia, hdegoede, mgross,
	jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, jack,
	tytso, adilger.kernel, dushistov, luc.vanoostenryck, rostedt,
	pmladek, senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
	akpm, yoshfuji, dsahern, pablo, kadlec, fw, jmaloy, ying.xue,
	shuah, willy, farbere, sashal, quic_akhilpo, ruanjinjie,
	David.Laight, herve.codina, linux-arm-kernel, linux-kernel,
	linux-um, linux-edac, amd-gfx, dri-devel, linux-arm-msm,
	freedreno, linux-hwmon, linux-input, linux-sunxi, linux-media,
	netdev, linux-stm32, platform-driver-x86, linux-scsi,
	linux-staging, linux-btrfs, linux-ext4, linux-sparse, linux-mm,
	netfilter-devel, coreteam, tipc-discussion, linux-kselftest,
	stable
  Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter,
	Jason A. Donenfeld, Jens Axboe, Lorenzo Stoakes, Mateusz Guzik,
	Pedro Falcato
In-Reply-To: <20251008152946.29285-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 v3 15/19 5.15.y] minmax.h: reduce the #define expansion of min(), max() and clamp()
From: Eliav Farber @ 2025-10-08 15:29 UTC (permalink / raw)
  To: gregkh, jdike, richard, anton.ivanov, dave.hansen, luto, peterz,
	tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, james.morse,
	rric, airlied, daniel, maarten.lankhorst, mripard, tzimmermann,
	robdclark, sean, jdelvare, linux, linus.walleij, dmitry.torokhov,
	maz, wens, jernej.skrabec, agk, snitzer, dm-devel, davem, kuba,
	mcoquelin.stm32, krzysztof.kozlowski, malattia, hdegoede, mgross,
	jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, jack,
	tytso, adilger.kernel, dushistov, luc.vanoostenryck, rostedt,
	pmladek, senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
	akpm, yoshfuji, dsahern, pablo, kadlec, fw, jmaloy, ying.xue,
	shuah, willy, farbere, sashal, quic_akhilpo, ruanjinjie,
	David.Laight, herve.codina, linux-arm-kernel, linux-kernel,
	linux-um, linux-edac, amd-gfx, dri-devel, linux-arm-msm,
	freedreno, linux-hwmon, linux-input, linux-sunxi, linux-media,
	netdev, linux-stm32, platform-driver-x86, linux-scsi,
	linux-staging, linux-btrfs, linux-ext4, linux-sparse, linux-mm,
	netfilter-devel, coreteam, tipc-discussion, linux-kselftest,
	stable
  Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter,
	Jason A. Donenfeld, Jens Axboe, Lorenzo Stoakes, Mateusz Guzik,
	Pedro Falcato
In-Reply-To: <20251008152946.29285-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 v3 14/19 5.15.y] minmax.h: update some comments
From: Eliav Farber @ 2025-10-08 15:29 UTC (permalink / raw)
  To: gregkh, jdike, richard, anton.ivanov, dave.hansen, luto, peterz,
	tglx, mingo, bp, x86, hpa, tony.luck, qiuxu.zhuo, james.morse,
	rric, airlied, daniel, maarten.lankhorst, mripard, tzimmermann,
	robdclark, sean, jdelvare, linux, linus.walleij, dmitry.torokhov,
	maz, wens, jernej.skrabec, agk, snitzer, dm-devel, davem, kuba,
	mcoquelin.stm32, krzysztof.kozlowski, malattia, hdegoede, mgross,
	jejb, martin.petersen, sakari.ailus, clm, josef, dsterba, jack,
	tytso, adilger.kernel, dushistov, luc.vanoostenryck, rostedt,
	pmladek, senozhatsky, andriy.shevchenko, linux, minchan, ngupta,
	akpm, yoshfuji, dsahern, pablo, kadlec, fw, jmaloy, ying.xue,
	shuah, willy, farbere, sashal, quic_akhilpo, ruanjinjie,
	David.Laight, herve.codina, linux-arm-kernel, linux-kernel,
	linux-um, linux-edac, amd-gfx, dri-devel, linux-arm-msm,
	freedreno, linux-hwmon, linux-input, linux-sunxi, linux-media,
	netdev, linux-stm32, platform-driver-x86, linux-scsi,
	linux-staging, linux-btrfs, linux-ext4, linux-sparse, linux-mm,
	netfilter-devel, coreteam, tipc-discussion, linux-kselftest,
	stable
  Cc: Arnd Bergmann, Christoph Hellwig, Dan Carpenter,
	Jason A. Donenfeld, Jens Axboe, Lorenzo Stoakes, Mateusz Guzik,
	Pedro Falcato
In-Reply-To: <20251008152946.29285-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


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox