diff mbox series

[v1,2/2] ACPICA: Silence 'unused-but-set variable' warning

Message ID 20221223142419.3781410-3-ammar.faizi@intel.com
State New
Headers show
Series clang warning cleanups | expand

Commit Message

Ammar Faizi Dec. 23, 2022, 2:24 p.m. UTC
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>

@num_carats is used for debugging, passed to the 'ACPI_DEBUG_PRINT()'
macro. But this macro will expand to nothing when debug is disabled,
resulting in the following (clang-16):

  drivers/acpi/acpica/nsaccess.c:295:6: error: variable 'num_carats' set \
  but not used [-Werror,-Wunused-but-set-variable]
        u32 num_carats;
            ^
  1 error generated.

Move the variable declaration inside the else block to reduce the scope,
then add '(void)num_carats' to silence the warning when debug is disabled.

Cc: LLVM Mailing List <llvm@lists.linux.dev>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 drivers/acpi/acpica/nsaccess.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Rafael J. Wysocki Dec. 30, 2022, 6:17 p.m. UTC | #1
On Fri, Dec 23, 2022 at 3:24 PM Ammar Faizi <ammarfaizi2@gnuweeb.org> wrote:
>
> From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
>
> @num_carats is used for debugging, passed to the 'ACPI_DEBUG_PRINT()'
> macro. But this macro will expand to nothing when debug is disabled,
> resulting in the following (clang-16):
>
>   drivers/acpi/acpica/nsaccess.c:295:6: error: variable 'num_carats' set \
>   but not used [-Werror,-Wunused-but-set-variable]
>         u32 num_carats;
>             ^
>   1 error generated.
>
> Move the variable declaration inside the else block to reduce the scope,
> then add '(void)num_carats' to silence the warning when debug is disabled.
>
> Cc: LLVM Mailing List <llvm@lists.linux.dev>
> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>

ACPICA changes require (at least) a pull request to be submitted to
the upstream ACPICA project on GitHub.

If such a pull request is created, please resend the Linux patch with
a Link tag pointing to that pull request.

Thanks!

> ---
>  drivers/acpi/acpica/nsaccess.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c
> index a0c1a665dfc1..d73d052c5b3b 100644
> --- a/drivers/acpi/acpica/nsaccess.c
> +++ b/drivers/acpi/acpica/nsaccess.c
> @@ -292,7 +292,6 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
>         struct acpi_namespace_node *current_node = NULL;
>         struct acpi_namespace_node *this_node = NULL;
>         u32 num_segments;
> -       u32 num_carats;
>         acpi_name simple_name;
>         acpi_object_type type_to_check_for;
>         acpi_object_type this_search_type;
> @@ -394,6 +393,7 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
>                                           "Path is absolute from root [%p]\n",
>                                           this_node));
>                 } else {
> +                       u32 num_carats = 0;
>                         /* Pathname is relative to current scope, start there */
>
>                         ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
> @@ -406,7 +406,6 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
>                          * the parent node for each prefix instance.
>                          */
>                         this_node = prefix_node;
> -                       num_carats = 0;
>                         while (*path == (u8) AML_PARENT_PREFIX) {
>
>                                 /* Name is fully qualified, no search rules apply */
> @@ -449,6 +448,7 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
>                                                   "Search scope is [%4.4s], path has %u carat(s)\n",
>                                                   acpi_ut_get_node_name
>                                                   (this_node), num_carats));
> +                               (void)num_carats;
>                         }
>                 }
>
> --
> Ammar Faizi
>
diff mbox series

Patch

diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c
index a0c1a665dfc1..d73d052c5b3b 100644
--- a/drivers/acpi/acpica/nsaccess.c
+++ b/drivers/acpi/acpica/nsaccess.c
@@ -292,7 +292,6 @@  acpi_ns_lookup(union acpi_generic_state *scope_info,
 	struct acpi_namespace_node *current_node = NULL;
 	struct acpi_namespace_node *this_node = NULL;
 	u32 num_segments;
-	u32 num_carats;
 	acpi_name simple_name;
 	acpi_object_type type_to_check_for;
 	acpi_object_type this_search_type;
@@ -394,6 +393,7 @@  acpi_ns_lookup(union acpi_generic_state *scope_info,
 					  "Path is absolute from root [%p]\n",
 					  this_node));
 		} else {
+			u32 num_carats = 0;
 			/* Pathname is relative to current scope, start there */
 
 			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
@@ -406,7 +406,6 @@  acpi_ns_lookup(union acpi_generic_state *scope_info,
 			 * the parent node for each prefix instance.
 			 */
 			this_node = prefix_node;
-			num_carats = 0;
 			while (*path == (u8) AML_PARENT_PREFIX) {
 
 				/* Name is fully qualified, no search rules apply */
@@ -449,6 +448,7 @@  acpi_ns_lookup(union acpi_generic_state *scope_info,
 						  "Search scope is [%4.4s], path has %u carat(s)\n",
 						  acpi_ut_get_node_name
 						  (this_node), num_carats));
+				(void)num_carats;
 			}
 		}