Skip to contentSkip to conversation

floppy: Avoid unsequenced accesses to jiffies in show_floppy()

PATCH Applied Nathan Chancellor 2 participants 2 messages Nov 15 – Nov 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 floppy: Avoid unsequenced accesses to jiffies in show_floppy()

After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in show_floppy(), which can break the build with CONFIG_WERROR=y / W=e:

drivers/block/floppy.c:1839:30: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]

   1839 |                 jiffies, interruptjiffies, jiffies - interruptjiffies,
        |                 ~~~~~~~                    ^

Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a function call is indeterminately sequenced, meaning any side effects in the arguments are unsequenced.

Add a local variable to hold the value of jiffies before the function call so that there are no unsequenced side effects, clearing up the warning.

---
 drivers/block/floppy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/floppy.c +2 -1
index c677d783811f..f6339d779be9 100644
@@ -1830,13 +1830,14 @@ static void reset_fdc(void)
 
 static void show_floppy(int fdc)
 {
+	unsigned long j = jiffies;
 	int i;
 
 	pr_info("\n");
 	pr_info("floppy driver state\n");
 	pr_info("-------------------\n");
 	pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%ps\n",
-		jiffies, interruptjiffies, jiffies - interruptjiffies,
+		j, interruptjiffies, j - interruptjiffies,
 		lasthandler);
 
 	pr_info("timeout_message=%s\n", timeout_message);

---
base-commit: ab43ec385580b8f8abf72d70fa3acbf4e4f098a5
change-id: 20261114-floppy-wunsequenced-8b739d08b849

Best regards,

Signature · 2 lines
Cheers,
Nathan
maintainer Applied
#1 lore raw

Hi,

Applied, thanks!

c1a8feb71ba8 floppy: Avoid unsequenced accesses to jiffies in show_floppy()

https://github.com/evdenis/linux-floppy branch for-7.5/floppy

Denis

Quoted 56 lines · Nathan Chancellor

After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in show_floppy(), which can break the build with CONFIG_WERROR=y / W=e:

drivers/block/floppy.c:1839:30: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]

   1839 |                 jiffies, interruptjiffies, jiffies - interruptjiffies,
        |                 ~~~~~~~                    ^

Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a function call is indeterminately sequenced, meaning any side effects in the arguments are unsequenced.

Add a local variable to hold the value of jiffies before the function call so that there are no unsequenced side effects, clearing up the warning.

---
 drivers/block/floppy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/floppy.c +2 -2
index c677d783811f..f6339d779be9 100644
@@ -1830,13 +1830,14 @@ static void reset_fdc(void)
 
 static void show_floppy(int fdc)
 {
+	unsigned long j = jiffies;
 	int i;
 
 	pr_info("\n");
 	pr_info("floppy driver state\n");
 	pr_info("-------------------\n");
 	pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%ps\n",
-		jiffies, interruptjiffies, jiffies - interruptjiffies,
+		j, interruptjiffies, j - interruptjiffies,
 		lasthandler);
 
 	pr_info("timeout_message=%s\n", timeout_message);
 
---

base-commit: ab43ec385580b8f8abf72d70fa3acbf4e4f098a5
change-id: 20261114-floppy-wunsequenced-8b739d08b849

Best regards,

Signature · 2 lines
Cheers,
Nathan