[PATCH 6.12] tools/power turbostat: Fix compilation on older compilers

Nikolay Kuratov posted 1 patch 2 days, 18 hours ago
tools/power/x86/turbostat/turbostat.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
[PATCH 6.12] tools/power turbostat: Fix compilation on older compilers
Posted by Nikolay Kuratov 2 days, 18 hours ago
Currently turbostat.c can't be built on pre-gcc-11 compilers
due to error: a label can only be part of a statement and a declaration
is not a statement.

Fix this by adding braces around case labels.

Fixes: 640540beb883 ("tools/power turbostat: Add MTL's PMT DC6 builtin counter")
Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
---
 tools/power/x86/turbostat/turbostat.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index b663a76d31f1..85d40d3c6384 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2799,7 +2799,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 
 	for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) {
 		switch (ppmt->type) {
-		case PMT_TYPE_RAW:
+		case PMT_TYPE_RAW: {
 			if (pmt_counter_get_width(ppmt) <= 32)
 				outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""),
 						(unsigned int)t->pmt_counter[i]);
@@ -2807,14 +2807,14 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 				outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->pmt_counter[i]);
 
 			break;
-
-		case PMT_TYPE_XTAL_TIME:
+		}
+		case PMT_TYPE_XTAL_TIME: {
 			const unsigned long value_raw = t->pmt_counter[i];
 			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
 
 			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
 			break;
-		}
+		}}
 	}
 
 	/* C1 */
@@ -2880,7 +2880,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 
 	for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) {
 		switch (ppmt->type) {
-		case PMT_TYPE_RAW:
+		case PMT_TYPE_RAW: {
 			if (pmt_counter_get_width(ppmt) <= 32)
 				outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""),
 						(unsigned int)c->pmt_counter[i]);
@@ -2888,14 +2888,14 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 				outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->pmt_counter[i]);
 
 			break;
-
-		case PMT_TYPE_XTAL_TIME:
+		}
+		case PMT_TYPE_XTAL_TIME: {
 			const unsigned long value_raw = c->pmt_counter[i];
 			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
 
 			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
 			break;
-		}
+		}}
 	}
 
 	fmt8 = "%s%.2f";
@@ -3079,7 +3079,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 
 	for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) {
 		switch (ppmt->type) {
-		case PMT_TYPE_RAW:
+		case PMT_TYPE_RAW: {
 			if (pmt_counter_get_width(ppmt) <= 32)
 				outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""),
 						(unsigned int)p->pmt_counter[i]);
@@ -3087,14 +3087,14 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 				outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->pmt_counter[i]);
 
 			break;
-
-		case PMT_TYPE_XTAL_TIME:
+		}
+		case PMT_TYPE_XTAL_TIME: {
 			const unsigned long value_raw = p->pmt_counter[i];
 			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
 
 			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
 			break;
-		}
+		}}
 	}
 
 done:
-- 
2.34.1
Re: [PATCH 6.12] tools/power turbostat: Fix compilation on older compilers
Posted by Greg KH 2 days, 18 hours ago
On Thu, Feb 05, 2026 at 06:59:07PM +0300, Nikolay Kuratov wrote:
> Currently turbostat.c can't be built on pre-gcc-11 compilers
> due to error: a label can only be part of a statement and a declaration
> is not a statement.
> 
> Fix this by adding braces around case labels.
> 
> Fixes: 640540beb883 ("tools/power turbostat: Add MTL's PMT DC6 builtin counter")
> Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
> ---
>  tools/power/x86/turbostat/turbostat.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
> index b663a76d31f1..85d40d3c6384 100644
> --- a/tools/power/x86/turbostat/turbostat.c
> +++ b/tools/power/x86/turbostat/turbostat.c
> @@ -2799,7 +2799,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
>  
>  	for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) {
>  		switch (ppmt->type) {
> -		case PMT_TYPE_RAW:
> +		case PMT_TYPE_RAW: {
>  			if (pmt_counter_get_width(ppmt) <= 32)
>  				outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""),
>  						(unsigned int)t->pmt_counter[i]);
> @@ -2807,14 +2807,14 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
>  				outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->pmt_counter[i]);
>  
>  			break;
> -
> -		case PMT_TYPE_XTAL_TIME:
> +		}
> +		case PMT_TYPE_XTAL_TIME: {
>  			const unsigned long value_raw = t->pmt_counter[i];
>  			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
>  
>  			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
>  			break;
> -		}
> +		}}
>  	}
>  
>  	/* C1 */
> @@ -2880,7 +2880,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
>  
>  	for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) {
>  		switch (ppmt->type) {
> -		case PMT_TYPE_RAW:
> +		case PMT_TYPE_RAW: {
>  			if (pmt_counter_get_width(ppmt) <= 32)
>  				outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""),
>  						(unsigned int)c->pmt_counter[i]);
> @@ -2888,14 +2888,14 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
>  				outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->pmt_counter[i]);
>  
>  			break;
> -
> -		case PMT_TYPE_XTAL_TIME:
> +		}
> +		case PMT_TYPE_XTAL_TIME: {
>  			const unsigned long value_raw = c->pmt_counter[i];
>  			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
>  
>  			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
>  			break;
> -		}
> +		}}
>  	}
>  
>  	fmt8 = "%s%.2f";
> @@ -3079,7 +3079,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
>  
>  	for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) {
>  		switch (ppmt->type) {
> -		case PMT_TYPE_RAW:
> +		case PMT_TYPE_RAW: {
>  			if (pmt_counter_get_width(ppmt) <= 32)
>  				outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""),
>  						(unsigned int)p->pmt_counter[i]);
> @@ -3087,14 +3087,14 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
>  				outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->pmt_counter[i]);
>  
>  			break;
> -
> -		case PMT_TYPE_XTAL_TIME:
> +		}
> +		case PMT_TYPE_XTAL_TIME: {
>  			const unsigned long value_raw = p->pmt_counter[i];
>  			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
>  
>  			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
>  			break;
> -		}
> +		}}
>  	}
>  
>  done:
> -- 
> 2.34.1
> 
> 

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>