From: Nathan Chancellor <nathan@kernel.org>
To: Armin Wolf <W_Armin@gmx.de>
Cc: kernel test robot <lkp@intel.com>,
ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com,
chumuzero@gmail.com, corbet@lwn.net, cs@tuxedo.de,
wse@tuxedocomputers.com, ggo@tuxedocomputers.com,
llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
platform-driver-x86@vger.kernel.org, rdunlap@infradead.org,
alok.a.tiwari@oracle.com, linux-leds@vger.kernel.org,
lee@kernel.org, pobrn@protonmail.com
Subject: Re: [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver
Date: Thu, 2 Oct 2025 16:36:27 -0700 [thread overview]
Message-ID: <20251002233627.GA3978676@ax162> (raw)
In-Reply-To: <6146d57b-f855-40b1-a644-3af6b28ceea4@gmx.de>
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
next prev parent reply other threads:[~2025-10-02 23:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-28 1:32 [PATCH v4 0/2] Add support for Uniwill laptop features Armin Wolf
2025-09-28 1:32 ` [PATCH v4 1/2] platform/x86: Add Uniwill laptop driver Armin Wolf
2025-09-28 20:42 ` kernel test robot
2025-10-02 18:41 ` Armin Wolf
2025-10-02 23:36 ` Nathan Chancellor [this message]
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
2025-09-30 13:43 ` Werner Sembach
2025-10-02 18:44 ` Armin Wolf
2025-09-28 1:32 ` [PATCH v4 2/2] Documentation: laptops: Add documentation for uniwill laptops Armin Wolf
2025-09-28 1:36 ` [PATCH v4 0/2] Add support for Uniwill laptop features Armin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251002233627.GA3978676@ax162 \
--to=nathan@kernel.org \
--cc=W_Armin@gmx.de \
--cc=alok.a.tiwari@oracle.com \
--cc=chumuzero@gmail.com \
--cc=corbet@lwn.net \
--cc=cs@tuxedo.de \
--cc=ggo@tuxedocomputers.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=lee@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=lkp@intel.com \
--cc=llvm@lists.linux.dev \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=platform-driver-x86@vger.kernel.org \
--cc=pobrn@protonmail.com \
--cc=rdunlap@infradead.org \
--cc=wse@tuxedocomputers.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.