LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] powerpc/powernv: fix variable "c" set but not used
@ 2019-05-23  2:31 Qian Cai
  2019-05-23  7:26 ` Christophe Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Qian Cai @ 2019-05-23  2:31 UTC (permalink / raw)
  To: benh, paulus, mpe; +Cc: aik, linuxppc-dev, linux-kernel, Qian Cai

The commit 58629c0dc349 ("powerpc/powernv/npu: Fault user page into the
hypervisor's pagetable") introduced a variable "c" to be used in
__get_user() and __get_user_nocheck() which need to stay as macros for
performance reasons, and "c" is not actually used in
pnv_npu2_handle_fault(),

arch/powerpc/platforms/powernv/npu-dma.c: In function 'pnv_npu2_handle_fault':
arch/powerpc/platforms/powernv/npu-dma.c:1122:7: warning: variable 'c'
set but not used [-Wunused-but-set-variable]

Fixed it by appending the __maybe_unused attribute, so compilers would
ignore it.

Signed-off-by: Qian Cai <cai@lca.pw>
---
 arch/powerpc/platforms/powernv/npu-dma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powernv/npu-dma.c b/arch/powerpc/platforms/powernv/npu-dma.c
index 495550432f3d..5bbe59573ee6 100644
--- a/arch/powerpc/platforms/powernv/npu-dma.c
+++ b/arch/powerpc/platforms/powernv/npu-dma.c
@@ -1119,7 +1119,8 @@ int pnv_npu2_handle_fault(struct npu_context *context, uintptr_t *ea,
 	int i, is_write;
 	struct page *page[1];
 	const char __user *u;
-	char c;
+	/* To silence a -Wunused-but-set-variable warning. */
+	char c __maybe_unused;
 
 	/* mmap_sem should be held so the struct_mm must be present */
 	struct mm_struct *mm = context->mm;
-- 
2.20.1 (Apple Git-117)


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

* Re: [PATCH] powerpc/powernv: fix variable "c" set but not used
  2019-05-23  2:31 [PATCH] powerpc/powernv: fix variable "c" set but not used Qian Cai
@ 2019-05-23  7:26 ` Christophe Leroy
  2019-05-23  7:46   ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Leroy @ 2019-05-23  7:26 UTC (permalink / raw)
  To: Qian Cai, benh, paulus, mpe; +Cc: aik, linuxppc-dev, linux-kernel



Le 23/05/2019 à 04:31, Qian Cai a écrit :
> The commit 58629c0dc349 ("powerpc/powernv/npu: Fault user page into the
> hypervisor's pagetable") introduced a variable "c" to be used in
> __get_user() and __get_user_nocheck() which need to stay as macros for
> performance reasons, and "c" is not actually used in
> pnv_npu2_handle_fault(),
> 
> arch/powerpc/platforms/powernv/npu-dma.c: In function 'pnv_npu2_handle_fault':
> arch/powerpc/platforms/powernv/npu-dma.c:1122:7: warning: variable 'c'
> set but not used [-Wunused-but-set-variable]
> 
> Fixed it by appending the __maybe_unused attribute, so compilers would
> ignore it.

You are not fixing the problem, you are just hiding it.

If the result of __get_user() is unneeded, it means __get_user() is not 
the good function to use.

Should use fault_in_pages_readable() instead.

A similar warning was fixed in commit 9f9eae5ce717 ("powerpc/kvm: Prefer 
fault_in_pages_readable function")

See 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/arch/powerpc?id=9f9eae5ce

> 
> Signed-off-by: Qian Cai <cai@lca.pw>

You should add a Fixes: tag

58629c0dc349 ("powerpc/powernv/npu: Fault user page into the 
hypervisor's pagetable")

Christophe

> ---
>   arch/powerpc/platforms/powernv/npu-dma.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/platforms/powernv/npu-dma.c b/arch/powerpc/platforms/powernv/npu-dma.c
> index 495550432f3d..5bbe59573ee6 100644
> --- a/arch/powerpc/platforms/powernv/npu-dma.c
> +++ b/arch/powerpc/platforms/powernv/npu-dma.c
> @@ -1119,7 +1119,8 @@ int pnv_npu2_handle_fault(struct npu_context *context, uintptr_t *ea,
>   	int i, is_write;
>   	struct page *page[1];
>   	const char __user *u;
> -	char c;
> +	/* To silence a -Wunused-but-set-variable warning. */
> +	char c __maybe_unused;
>   
>   	/* mmap_sem should be held so the struct_mm must be present */
>   	struct mm_struct *mm = context->mm;
> 

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

* Re: [PATCH] powerpc/powernv: fix variable "c" set but not used
  2019-05-23  7:26 ` Christophe Leroy
@ 2019-05-23  7:46   ` Christoph Hellwig
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2019-05-23  7:46 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Qian Cai, benh, paulus, mpe, aik, linuxppc-dev, linux-kernel

On Thu, May 23, 2019 at 09:26:53AM +0200, Christophe Leroy wrote:
> You are not fixing the problem, you are just hiding it.
> 
> If the result of __get_user() is unneeded, it means __get_user() is not the
> good function to use.
> 
> Should use fault_in_pages_readable() instead.

Also it is not just the variable that is unused, but that whole
function.  I'll resend my series to remote it in a bit.

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

end of thread, other threads:[~2019-05-23  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23  2:31 [PATCH] powerpc/powernv: fix variable "c" set but not used Qian Cai
2019-05-23  7:26 ` Christophe Leroy
2019-05-23  7:46   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).