linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] zynq: clkc: Add kmalloc allocation flag
  2023-02-22 21:58 [PATCH] zynq: clkc: Add kmalloc allocation flag Li zeming
@ 2023-02-21 22:50 ` Stephen Boyd
  2023-02-23 18:33   ` Li zeming
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2023-02-21 22:50 UTC (permalink / raw)
  To: Li zeming, michal.simek, mturquette
  Cc: linux-clk, linux-arm-kernel, linux-kernel, Li zeming

Quoting Li zeming (2023-02-22 13:58:34)
> The kmalloc could crash if allocation fails. Add the __GFP_NOFAIL flag
> to ensure that allocation succeeds every time.
> 
> Signed-off-by: Li zeming <zeming@nfschina.com>
> ---
>  drivers/clk/zynq/clkc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
> index 7bdeaff2bfd6..7621c2f00468 100644
> --- a/drivers/clk/zynq/clkc.c
> +++ b/drivers/clk/zynq/clkc.c
> @@ -427,7 +427,7 @@ static void __init zynq_clk_setup(struct device_node *np)
>                         SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock);
>  
>         tmp = strlen("mio_clk_00x");
> -       clk_name = kmalloc(tmp, GFP_KERNEL);
> +       clk_name = kmalloc(tmp, GFP_KERNEL | __GFP_NOFAIL);

There are so many more allocations happening in this function and they
aren't marked nofail. Why is this one special?

I could see a patch moving mio_clk_00x to the stack and then printing to
it. But it is also fine like this, so I don't see any reason to change
this.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH] zynq: clkc: Add kmalloc allocation flag
@ 2023-02-22 21:58 Li zeming
  2023-02-21 22:50 ` Stephen Boyd
  0 siblings, 1 reply; 4+ messages in thread
From: Li zeming @ 2023-02-22 21:58 UTC (permalink / raw)
  To: mturquette, sboyd, michal.simek
  Cc: linux-clk, linux-arm-kernel, linux-kernel, Li zeming

The kmalloc could crash if allocation fails. Add the __GFP_NOFAIL flag
to ensure that allocation succeeds every time.

Signed-off-by: Li zeming <zeming@nfschina.com>
---
 drivers/clk/zynq/clkc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
index 7bdeaff2bfd6..7621c2f00468 100644
--- a/drivers/clk/zynq/clkc.c
+++ b/drivers/clk/zynq/clkc.c
@@ -427,7 +427,7 @@ static void __init zynq_clk_setup(struct device_node *np)
 			SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock);
 
 	tmp = strlen("mio_clk_00x");
-	clk_name = kmalloc(tmp, GFP_KERNEL);
+	clk_name = kmalloc(tmp, GFP_KERNEL | __GFP_NOFAIL);
 	for (i = 0; i < NUM_MIO_PINS; i++) {
 		int idx;
 
-- 
2.18.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] zynq: clkc: Add kmalloc allocation flag
  2023-02-21 22:50 ` Stephen Boyd
@ 2023-02-23 18:33   ` Li zeming
  2023-02-27 14:38     ` Michal Simek
  0 siblings, 1 reply; 4+ messages in thread
From: Li zeming @ 2023-02-23 18:33 UTC (permalink / raw)
  To: sboyd; +Cc: linux-arm-kernel, linux-clk, linux-kernel, michal.simek,
	mturquette


hello senior:
  I observed that some other variable assignments in this function are basically judged by the if statement, while clk_name does not make an if branch statement, and I think clk_name is also relatively important, increasing __GFP_NOFAIL flag ensures that the assignment can succeed under any circumstances.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] zynq: clkc: Add kmalloc allocation flag
  2023-02-23 18:33   ` Li zeming
@ 2023-02-27 14:38     ` Michal Simek
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Simek @ 2023-02-27 14:38 UTC (permalink / raw)
  To: Li zeming, sboyd
  Cc: linux-arm-kernel, linux-clk, linux-kernel, michal.simek,
	mturquette

Hi,

On 2/23/23 19:33, Li zeming wrote:
> 
> hello senior:
>    I observed that some other variable assignments in this function are basically judged by the if statement, while clk_name does not make an if branch statement, and I think clk_name is also relatively important, increasing __GFP_NOFAIL flag ensures that the assignment can succeed under any circumstances.
> 

I think that solution with array on stack would be better choice.
It will be faster and you can completely skip the whole allocation code for it.

Thanks,
Michal


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-02-27 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-22 21:58 [PATCH] zynq: clkc: Add kmalloc allocation flag Li zeming
2023-02-21 22:50 ` Stephen Boyd
2023-02-23 18:33   ` Li zeming
2023-02-27 14:38     ` Michal Simek

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).