Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
       [not found] <20250928013253.10869-2-W_Armin@gmx.de>
@ 2025-09-28 20:42 ` kernel test robot
  2025-10-02 18:41   ` Armin Wolf
  2025-09-30  9:15 ` kernel test robot
  1 sibling, 1 reply; 7+ messages in thread
From: kernel test robot @ 2025-09-28 20:42 UTC (permalink / raw)
  To: Armin Wolf, ilpo.jarvinen, hdegoede, chumuzero, corbet, cs, wse,
	ggo
  Cc: llvm, oe-kbuild-all, linux-doc, linux-kernel, platform-driver-x86,
	rdunlap, alok.a.tiwari, linux-leds, lee, pobrn

Hi Armin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on lwn/docs-next]
[also build test WARNING on linus/master v6.17-rc7 next-20250926]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Armin-Wolf/platform-x86-Add-Uniwill-laptop-driver/20250928-093543
base:   git://git.lwn.net/linux.git docs-next
patch link:    https://lore.kernel.org/r/20250928013253.10869-2-W_Armin%40gmx.de
patch subject: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250929/202509290415.uez00SgW-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250929/202509290415.uez00SgW-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509290415.uez00SgW-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/platform/x86/uniwill/uniwill-acpi.c:1243:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
    1243 |                 guard(mutex)(&data->battery_lock);
         |                 ^
   include/linux/cleanup.h:401:2: note: expanded from macro 'guard'
     401 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^
   include/linux/cleanup.h:290:2: note: expanded from macro 'CLASS'
     290 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
         |         ^
   <scratch space>:49:1: note: expanded from here
      49 | class_mutex_t
         | ^
   drivers/platform/x86/uniwill/uniwill-acpi.c:1250:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
    1250 |                 guard(mutex)(&data->input_lock);
         |                 ^
   include/linux/cleanup.h:401:2: note: expanded from macro 'guard'
     401 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^
   include/linux/cleanup.h:290:2: note: expanded from macro 'CLASS'
     290 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
         |         ^
   <scratch space>:60:1: note: expanded from here
      60 | class_mutex_t
         | ^
   drivers/platform/x86/uniwill/uniwill-acpi.c:1249:2: error: cannot jump from switch statement to this case label
    1249 |         default:
         |         ^
   drivers/platform/x86/uniwill/uniwill-acpi.c:1243:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
    1243 |                 guard(mutex)(&data->battery_lock);
         |                 ^
   include/linux/cleanup.h:401:15: note: expanded from macro 'guard'
     401 |         CLASS(_name, __UNIQUE_ID(guard))
         |                      ^
   include/linux/compiler.h:166:29: note: expanded from macro '__UNIQUE_ID'
     166 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:47:1: note: expanded from here
      47 | __UNIQUE_ID_guard1072
         | ^
   2 warnings and 1 error generated.


vim +1243 drivers/platform/x86/uniwill/uniwill-acpi.c

  1235	
  1236	static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action, void *dummy)
  1237	{
  1238		struct uniwill_data *data = container_of(nb, struct uniwill_data, nb);
  1239		struct uniwill_battery_entry *entry;
  1240	
  1241		switch (action) {
  1242		case UNIWILL_OSD_BATTERY_ALERT:
> 1243			guard(mutex)(&data->battery_lock);
  1244			list_for_each_entry(entry, &data->batteries, head) {
  1245				power_supply_changed(entry->battery);
  1246			}
  1247	
  1248			return NOTIFY_OK;
  1249		default:
  1250			guard(mutex)(&data->input_lock);
  1251			sparse_keymap_report_event(data->input_device, action, 1, true);
  1252	
  1253			return NOTIFY_OK;
  1254		}
  1255	}
  1256	

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
       [not found] <20250928013253.10869-2-W_Armin@gmx.de>
  2025-09-28 20:42 ` [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver kernel test robot
@ 2025-09-30  9:15 ` kernel test robot
  1 sibling, 0 replies; 7+ messages in thread
From: kernel test robot @ 2025-09-30  9:15 UTC (permalink / raw)
  To: Armin Wolf, ilpo.jarvinen, hdegoede, chumuzero, corbet, cs, wse,
	ggo
  Cc: llvm, oe-kbuild-all, linux-doc, linux-kernel, platform-driver-x86,
	rdunlap, alok.a.tiwari, linux-leds, lee, pobrn

Hi Armin,

kernel test robot noticed the following build errors:

[auto build test ERROR on lwn/docs-next]
[also build test ERROR on linus/master v6.17 next-20250929]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Armin-Wolf/platform-x86-Add-Uniwill-laptop-driver/20250928-093543
base:   git://git.lwn.net/linux.git docs-next
patch link:    https://lore.kernel.org/r/20250928013253.10869-2-W_Armin%40gmx.de
patch subject: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250930/202509301709.jGxwZmZX-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250930/202509301709.jGxwZmZX-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509301709.jGxwZmZX-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/platform/x86/uniwill/uniwill-acpi.c:1243:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
    1243 |                 guard(mutex)(&data->battery_lock);
         |                 ^
   include/linux/cleanup.h:401:2: note: expanded from macro 'guard'
     401 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^
   include/linux/cleanup.h:290:2: note: expanded from macro 'CLASS'
     290 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
         |         ^
   <scratch space>:49:1: note: expanded from here
      49 | class_mutex_t
         | ^
   drivers/platform/x86/uniwill/uniwill-acpi.c:1250:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
    1250 |                 guard(mutex)(&data->input_lock);
         |                 ^
   include/linux/cleanup.h:401:2: note: expanded from macro 'guard'
     401 |         CLASS(_name, __UNIQUE_ID(guard))
         |         ^
   include/linux/cleanup.h:290:2: note: expanded from macro 'CLASS'
     290 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
         |         ^
   <scratch space>:60:1: note: expanded from here
      60 | class_mutex_t
         | ^
>> drivers/platform/x86/uniwill/uniwill-acpi.c:1249:2: error: cannot jump from switch statement to this case label
    1249 |         default:
         |         ^
   drivers/platform/x86/uniwill/uniwill-acpi.c:1243:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
    1243 |                 guard(mutex)(&data->battery_lock);
         |                 ^
   include/linux/cleanup.h:401:15: note: expanded from macro 'guard'
     401 |         CLASS(_name, __UNIQUE_ID(guard))
         |                      ^
   include/linux/compiler.h:166:29: note: expanded from macro '__UNIQUE_ID'
     166 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:47:1: note: expanded from here
      47 | __UNIQUE_ID_guard1072
         | ^
   2 warnings and 1 error generated.


vim +1249 drivers/platform/x86/uniwill/uniwill-acpi.c

  1235	
  1236	static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action, void *dummy)
  1237	{
  1238		struct uniwill_data *data = container_of(nb, struct uniwill_data, nb);
  1239		struct uniwill_battery_entry *entry;
  1240	
  1241		switch (action) {
  1242		case UNIWILL_OSD_BATTERY_ALERT:
  1243			guard(mutex)(&data->battery_lock);
  1244			list_for_each_entry(entry, &data->batteries, head) {
  1245				power_supply_changed(entry->battery);
  1246			}
  1247	
  1248			return NOTIFY_OK;
> 1249		default:
  1250			guard(mutex)(&data->input_lock);
  1251			sparse_keymap_report_event(data->input_device, action, 1, true);
  1252	
  1253			return NOTIFY_OK;
  1254		}
  1255	}
  1256	

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
  2025-09-28 20:42 ` [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver kernel test robot
@ 2025-10-02 18:41   ` Armin Wolf
  2025-10-02 23:36     ` Nathan Chancellor
  0 siblings, 1 reply; 7+ messages in thread
From: Armin Wolf @ 2025-10-02 18:41 UTC (permalink / raw)
  To: kernel test robot, ilpo.jarvinen, hdegoede, chumuzero, corbet, cs,
	wse, ggo
  Cc: llvm, oe-kbuild-all, linux-doc, linux-kernel, platform-driver-x86,
	rdunlap, alok.a.tiwari, linux-leds, lee, pobrn

Am 28.09.25 um 22:42 schrieb kernel test robot:

> Hi Armin,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on lwn/docs-next]
> [also build test WARNING on linus/master v6.17-rc7 next-20250926]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Armin-Wolf/platform-x86-Add-Uniwill-laptop-driver/20250928-093543
> base:   git://git.lwn.net/linux.git docs-next
> patch link:    https://lore.kernel.org/r/20250928013253.10869-2-W_Armin%40gmx.de
> patch subject: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
> config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250929/202509290415.uez00SgW-lkp@intel.com/config)
> compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250929/202509290415.uez00SgW-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202509290415.uez00SgW-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
>>> drivers/platform/x86/uniwill/uniwill-acpi.c:1243:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
>      1243 |                 guard(mutex)(&data->battery_lock);
>           |                 ^
>     include/linux/cleanup.h:401:2: note: expanded from macro 'guard'
>       401 |         CLASS(_name, __UNIQUE_ID(guard))
>           |         ^
>     include/linux/cleanup.h:290:2: note: expanded from macro 'CLASS'
>       290 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
>           |         ^
>     <scratch space>:49:1: note: expanded from here
>        49 | class_mutex_t
>           | ^
>     drivers/platform/x86/uniwill/uniwill-acpi.c:1250:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
>      1250 |                 guard(mutex)(&data->input_lock);
>           |                 ^
>     include/linux/cleanup.h:401:2: note: expanded from macro 'guard'
>       401 |         CLASS(_name, __UNIQUE_ID(guard))
>           |         ^
>     include/linux/cleanup.h:290:2: note: expanded from macro 'CLASS'
>       290 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
>           |         ^
>     <scratch space>:60:1: note: expanded from here
>        60 | class_mutex_t
>           | ^
>     drivers/platform/x86/uniwill/uniwill-acpi.c:1249:2: error: cannot jump from switch statement to this case label
>      1249 |         default:
>           |         ^
>     drivers/platform/x86/uniwill/uniwill-acpi.c:1243:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
>      1243 |                 guard(mutex)(&data->battery_lock);
>           |                 ^
>     include/linux/cleanup.h:401:15: note: expanded from macro 'guard'
>       401 |         CLASS(_name, __UNIQUE_ID(guard))
>           |                      ^
>     include/linux/compiler.h:166:29: note: expanded from macro '__UNIQUE_ID'
>       166 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
>           |                             ^
>     include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
>        84 | #define __PASTE(a,b) ___PASTE(a,b)
>           |                      ^
>     include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
>        83 | #define ___PASTE(a,b) a##b
>           |                       ^
>     <scratch space>:47:1: note: expanded from here
>        47 | __UNIQUE_ID_guard1072
>           | ^
>     2 warnings and 1 error generated.
>
Hi,

i think this is a problem inside the clang compiler. I did not encounter this warning when
build for x86-64 using gcc.

Thanks,
Armin Wolf

> vim +1243 drivers/platform/x86/uniwill/uniwill-acpi.c
>
>    1235	
>    1236	static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action, void *dummy)
>    1237	{
>    1238		struct uniwill_data *data = container_of(nb, struct uniwill_data, nb);
>    1239		struct uniwill_battery_entry *entry;
>    1240	
>    1241		switch (action) {
>    1242		case UNIWILL_OSD_BATTERY_ALERT:
>> 1243			guard(mutex)(&data->battery_lock);
>    1244			list_for_each_entry(entry, &data->batteries, head) {
>    1245				power_supply_changed(entry->battery);
>    1246			}
>    1247	
>    1248			return NOTIFY_OK;
>    1249		default:
>    1250			guard(mutex)(&data->input_lock);
>    1251			sparse_keymap_report_event(data->input_device, action, 1, true);
>    1252	
>    1253			return NOTIFY_OK;
>    1254		}
>    1255	}
>    1256	
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
  2025-10-02 18:41   ` Armin Wolf
@ 2025-10-02 23:36     ` Nathan Chancellor
  2025-10-05 18:06       ` Armin Wolf
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2025-10-02 23:36 UTC (permalink / raw)
  To: Armin Wolf
  Cc: kernel test robot, ilpo.jarvinen, hdegoede, chumuzero, corbet, cs,
	wse, ggo, llvm, oe-kbuild-all, linux-doc, linux-kernel,
	platform-driver-x86, rdunlap, alok.a.tiwari, linux-leds, lee,
	pobrn

Hi Armin,

On Thu, Oct 02, 2025 at 08:41:19PM +0200, Armin Wolf wrote:
> i think this is a problem inside the clang compiler. I did not encounter this warning when
> build for x86-64 using gcc.

Clang is actually saving you from yourself, it is a bug in GCC that it
does not warn for this:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91951

> > vim +1243 drivers/platform/x86/uniwill/uniwill-acpi.c
> > 
> >    1235	
> >    1236	static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action, void *dummy)
> >    1237	{
> >    1238		struct uniwill_data *data = container_of(nb, struct uniwill_data, nb);
> >    1239		struct uniwill_battery_entry *entry;
> >    1240	
> >    1241		switch (action) {
> >    1242		case UNIWILL_OSD_BATTERY_ALERT:
> > > 1243			guard(mutex)(&data->battery_lock);

mutex_unlock() will be called on &data->battery_lock even when the
default case is taken, as demonstrated by the following test case.

> >    1244			list_for_each_entry(entry, &data->batteries, head) {
> >    1245				power_supply_changed(entry->battery);
> >    1246			}
> >    1247	
> >    1248			return NOTIFY_OK;
> >    1249		default:
> >    1250			guard(mutex)(&data->input_lock);
> >    1251			sparse_keymap_report_event(data->input_device, action, 1, true);
> >    1252	
> >    1253			return NOTIFY_OK;
> >    1254		}
> >    1255	}
> >    1256	
> > 
> 

$ cat test.c
#include <stdio.h>

void cleanup_1(int *a) { printf("+ %s(%p)\n", __func__, a); }
void cleanup_2(int *a) { printf("+ %s(%p)\n", __func__, a); }
void cleanup_3(int *a) { printf("+ %s(%p)\n", __func__, a); }

void no_scopes(int a)
{
    printf("%s(%d)\n", __func__, a);
    switch (a) {
    case 1:
        int case_1 __attribute__((cleanup(cleanup_1)));
        return;
    case 2:
        int case_2 __attribute__((cleanup(cleanup_2)));
        return;
    default:
        int case_default __attribute__((cleanup(cleanup_3)));
        return;
    }
}

void with_scopes(int a)
{
    printf("%s(%d)\n", __func__, a);
    switch (a) {
    case 1: {
        int case_1 __attribute__((cleanup(cleanup_1)));
        return;
    }
    case 2: {
        int case_2 __attribute__((cleanup(cleanup_2)));
        return;
    }
    default: {
        int case_default __attribute__((cleanup(cleanup_3)));
        return;
    }
    }
}

int main(void)
{
    no_scopes(1); printf("\n");
    no_scopes(2); printf("\n");
    no_scopes(3); printf("\n");

    with_scopes(1); printf("\n");
    with_scopes(2); printf("\n");
    with_scopes(3);
}

$ gcc -O2 test.c

$ ./a.out
no_scopes(1)
+ cleanup_1(0x7ffea3450c0c)

no_scopes(2)
+ cleanup_2(0x7ffea3450c10)
+ cleanup_1(0x7ffea3450c0c)

no_scopes(3)
+ cleanup_3(0x7ffea3450c14)
+ cleanup_2(0x7ffea3450c10)
+ cleanup_1(0x7ffea3450c0c)

with_scopes(1)
+ cleanup_1(0x7ffea3450c14)

with_scopes(2)
+ cleanup_2(0x7ffea3450c14)

with_scopes(3)
+ cleanup_3(0x7ffea3450c14)

$ clang -O2 test.c
test.c:12:9: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
   12 |         int case_1 __attribute__((cleanup(cleanup_1)));
      |         ^
test.c:15:9: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
   15 |         int case_2 __attribute__((cleanup(cleanup_2)));
      |         ^
test.c:18:9: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
   18 |         int case_default __attribute__((cleanup(cleanup_3)));
      |         ^
test.c:17:5: error: cannot jump from switch statement to this case label
   17 |     default:
      |     ^
test.c:15:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
   15 |         int case_2 __attribute__((cleanup(cleanup_2)));
      |             ^
test.c:12:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
   12 |         int case_1 __attribute__((cleanup(cleanup_1)));
      |             ^
test.c:14:5: error: cannot jump from switch statement to this case label
   14 |     case 2:
      |     ^
test.c:12:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
   12 |         int case_1 __attribute__((cleanup(cleanup_1)));
      |             ^
3 warnings and 2 errors generated.

https://godbolt.org/z/1Tx7Gj1xf

I would add the scoping to the case labels or use scoped_guard() to
avoid this, which would also avoid the instances of -Wc23-extensions.

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
  2025-10-02 23:36     ` Nathan Chancellor
@ 2025-10-05 18:06       ` Armin Wolf
  2025-10-06 19:08         ` Nathan Chancellor
  0 siblings, 1 reply; 7+ messages in thread
From: Armin Wolf @ 2025-10-05 18:06 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: kernel test robot, ilpo.jarvinen, hdegoede, chumuzero, corbet, cs,
	wse, ggo, llvm, oe-kbuild-all, linux-doc, linux-kernel,
	platform-driver-x86, rdunlap, alok.a.tiwari, linux-leds, lee,
	pobrn

Am 03.10.25 um 01:36 schrieb Nathan Chancellor:

> Hi Armin,
>
> On Thu, Oct 02, 2025 at 08:41:19PM +0200, Armin Wolf wrote:
>> i think this is a problem inside the clang compiler. I did not encounter this warning when
>> build for x86-64 using gcc.
> Clang is actually saving you from yourself, it is a bug in GCC that it
> does not warn for this:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91951

Oh my, i didn't expect that. Thank you for explaining this issue to to me,
it seems that i still have much to learn.

Thanks,
Armin Wolf

>>> vim +1243 drivers/platform/x86/uniwill/uniwill-acpi.c
>>>
>>>     1235	
>>>     1236	static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action, void *dummy)
>>>     1237	{
>>>     1238		struct uniwill_data *data = container_of(nb, struct uniwill_data, nb);
>>>     1239		struct uniwill_battery_entry *entry;
>>>     1240	
>>>     1241		switch (action) {
>>>     1242		case UNIWILL_OSD_BATTERY_ALERT:
>>>> 1243			guard(mutex)(&data->battery_lock);
> mutex_unlock() will be called on &data->battery_lock even when the
> default case is taken, as demonstrated by the following test case.
>
>>>     1244			list_for_each_entry(entry, &data->batteries, head) {
>>>     1245				power_supply_changed(entry->battery);
>>>     1246			}
>>>     1247	
>>>     1248			return NOTIFY_OK;
>>>     1249		default:
>>>     1250			guard(mutex)(&data->input_lock);
>>>     1251			sparse_keymap_report_event(data->input_device, action, 1, true);
>>>     1252	
>>>     1253			return NOTIFY_OK;
>>>     1254		}
>>>     1255	}
>>>     1256	
>>>
> $ cat test.c
> #include <stdio.h>
>
> void cleanup_1(int *a) { printf("+ %s(%p)\n", __func__, a); }
> void cleanup_2(int *a) { printf("+ %s(%p)\n", __func__, a); }
> void cleanup_3(int *a) { printf("+ %s(%p)\n", __func__, a); }
>
> void no_scopes(int a)
> {
>      printf("%s(%d)\n", __func__, a);
>      switch (a) {
>      case 1:
>          int case_1 __attribute__((cleanup(cleanup_1)));
>          return;
>      case 2:
>          int case_2 __attribute__((cleanup(cleanup_2)));
>          return;
>      default:
>          int case_default __attribute__((cleanup(cleanup_3)));
>          return;
>      }
> }
>
> void with_scopes(int a)
> {
>      printf("%s(%d)\n", __func__, a);
>      switch (a) {
>      case 1: {
>          int case_1 __attribute__((cleanup(cleanup_1)));
>          return;
>      }
>      case 2: {
>          int case_2 __attribute__((cleanup(cleanup_2)));
>          return;
>      }
>      default: {
>          int case_default __attribute__((cleanup(cleanup_3)));
>          return;
>      }
>      }
> }
>
> int main(void)
> {
>      no_scopes(1); printf("\n");
>      no_scopes(2); printf("\n");
>      no_scopes(3); printf("\n");
>
>      with_scopes(1); printf("\n");
>      with_scopes(2); printf("\n");
>      with_scopes(3);
> }
>
> $ gcc -O2 test.c
>
> $ ./a.out
> no_scopes(1)
> + cleanup_1(0x7ffea3450c0c)
>
> no_scopes(2)
> + cleanup_2(0x7ffea3450c10)
> + cleanup_1(0x7ffea3450c0c)
>
> no_scopes(3)
> + cleanup_3(0x7ffea3450c14)
> + cleanup_2(0x7ffea3450c10)
> + cleanup_1(0x7ffea3450c0c)
>
> with_scopes(1)
> + cleanup_1(0x7ffea3450c14)
>
> with_scopes(2)
> + cleanup_2(0x7ffea3450c14)
>
> with_scopes(3)
> + cleanup_3(0x7ffea3450c14)
>
> $ clang -O2 test.c
> test.c:12:9: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
>     12 |         int case_1 __attribute__((cleanup(cleanup_1)));
>        |         ^
> test.c:15:9: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
>     15 |         int case_2 __attribute__((cleanup(cleanup_2)));
>        |         ^
> test.c:18:9: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
>     18 |         int case_default __attribute__((cleanup(cleanup_3)));
>        |         ^
> test.c:17:5: error: cannot jump from switch statement to this case label
>     17 |     default:
>        |     ^
> test.c:15:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
>     15 |         int case_2 __attribute__((cleanup(cleanup_2)));
>        |             ^
> test.c:12:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
>     12 |         int case_1 __attribute__((cleanup(cleanup_1)));
>        |             ^
> test.c:14:5: error: cannot jump from switch statement to this case label
>     14 |     case 2:
>        |     ^
> test.c:12:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
>     12 |         int case_1 __attribute__((cleanup(cleanup_1)));
>        |             ^
> 3 warnings and 2 errors generated.
>
> https://godbolt.org/z/1Tx7Gj1xf
>
> I would add the scoping to the case labels or use scoped_guard() to
> avoid this, which would also avoid the instances of -Wc23-extensions.
>
> Cheers,
> Nathan
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
  2025-10-05 18:06       ` Armin Wolf
@ 2025-10-06 19:08         ` Nathan Chancellor
  2025-10-17 17:19           ` Armin Wolf
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2025-10-06 19:08 UTC (permalink / raw)
  To: Armin Wolf
  Cc: kernel test robot, ilpo.jarvinen, hdegoede, chumuzero, corbet, cs,
	wse, ggo, llvm, oe-kbuild-all, linux-doc, linux-kernel,
	platform-driver-x86, rdunlap, alok.a.tiwari, linux-leds, lee,
	pobrn

On Sun, Oct 05, 2025 at 08:06:57PM +0200, Armin Wolf wrote:
> Am 03.10.25 um 01:36 schrieb Nathan Chancellor:
> 
> > Hi Armin,
> > 
> > On Thu, Oct 02, 2025 at 08:41:19PM +0200, Armin Wolf wrote:
> > > i think this is a problem inside the clang compiler. I did not encounter this warning when
> > > build for x86-64 using gcc.
> > Clang is actually saving you from yourself, it is a bug in GCC that it
> > does not warn for this:
> > 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91951
> 
> Oh my, i didn't expect that. Thank you for explaining this issue to to me,
> it seems that i still have much to learn.

In your defense, it is quite a subtle interaction. It is probably worth
throwing something in the documentation that explicitly calls this out,
though I am not immediately sure of where...

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
  2025-10-06 19:08         ` Nathan Chancellor
@ 2025-10-17 17:19           ` Armin Wolf
  0 siblings, 0 replies; 7+ messages in thread
From: Armin Wolf @ 2025-10-17 17:19 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: kernel test robot, ilpo.jarvinen, hdegoede, chumuzero, corbet, cs,
	wse, ggo, llvm, oe-kbuild-all, linux-doc, linux-kernel,
	platform-driver-x86, rdunlap, alok.a.tiwari, linux-leds, lee,
	pobrn

Am 06.10.25 um 21:08 schrieb Nathan Chancellor:

> On Sun, Oct 05, 2025 at 08:06:57PM +0200, Armin Wolf wrote:
>> Am 03.10.25 um 01:36 schrieb Nathan Chancellor:
>>
>>> Hi Armin,
>>>
>>> On Thu, Oct 02, 2025 at 08:41:19PM +0200, Armin Wolf wrote:
>>>> i think this is a problem inside the clang compiler. I did not encounter this warning when
>>>> build for x86-64 using gcc.
>>> Clang is actually saving you from yourself, it is a bug in GCC that it
>>> does not warn for this:
>>>
>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91951
>> Oh my, i didn't expect that. Thank you for explaining this issue to to me,
>> it seems that i still have much to learn.
> In your defense, it is quite a subtle interaction. It is probably worth
> throwing something in the documentation that explicitly calls this out,
> though I am not immediately sure of where...
>
> Cheers,
> Nathan
>
Maybe Documentation/core-api/cleanup.rst would be a suitable place for warning
people about this.

Thanks,
Armin Wolf


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-10-17 17:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250928013253.10869-2-W_Armin@gmx.de>
2025-09-28 20:42 ` [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver kernel test robot
2025-10-02 18:41   ` Armin Wolf
2025-10-02 23:36     ` Nathan Chancellor
2025-10-05 18:06       ` Armin Wolf
2025-10-06 19:08         ` Nathan Chancellor
2025-10-17 17:19           ` Armin Wolf
2025-09-30  9:15 ` kernel test robot

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