public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: fix member type of struct clk_hw_onecell_data
@ 2016-04-25  2:50 Masahiro Yamada
  2016-04-25 22:27 ` Stephen Boyd
  0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2016-04-25  2:50 UTC (permalink / raw)
  To: linux-clk; +Cc: Masahiro Yamada, Stephen Boyd, Michael Turquette, linux-kernel

We cannot assign any value to an array type variable.  So,

  hw_data->hws = kcalloc(hw_data->num, sizeof(struct clk_hw *),
                         GFP_KERNEL);

fails with "invalid use of flexible array member" error.

There are two ways to fix this issue.

[1] Make it a double-pointer
  struct clk_hw_onecell_data {
          size_t num;
          struct clk_hw **hws;
  };

This works as struct clk_onecell_data does.

[2] Make it a zero-sized array
  struct clk_hw_onecell_data {
          size_t num;
          struct clk_hw *hws[0];
  };

This allows one-shot memory allocation like this:

  hw_data = kmalloc(sizeof(*hw_data) + clk_num * sizeof(struct clk_hw *),
                    GFP_KERNEL);

This commit adopts [2] because it looks like Stephen's intention
(he moved hws[] to the bottom of struct clk_hw_onecell_data).

Fixes: 0861e5b8cf80 ("clk: Add clk_hw OF clk providers")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 include/linux/clk-provider.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index fd2ccd5..1850e25 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -769,7 +769,7 @@ struct clk_onecell_data {
 
 struct clk_hw_onecell_data {
 	size_t num;
-	struct clk_hw *hws[];
+	struct clk_hw *hws[0];
 };
 
 extern struct of_device_id __clk_of_table;
-- 
1.9.1

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

* Re: [PATCH] clk: fix member type of struct clk_hw_onecell_data
  2016-04-25  2:50 [PATCH] clk: fix member type of struct clk_hw_onecell_data Masahiro Yamada
@ 2016-04-25 22:27 ` Stephen Boyd
  2016-04-26  6:19   ` Masahiro Yamada
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Boyd @ 2016-04-25 22:27 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-clk, Michael Turquette, linux-kernel

On 04/25, Masahiro Yamada wrote:
> We cannot assign any value to an array type variable.  So,
> 
>   hw_data->hws = kcalloc(hw_data->num, sizeof(struct clk_hw *),
>                          GFP_KERNEL);
> 
> fails with "invalid use of flexible array member" error.

That's good. We don't want assignment to the hws member of this
structure to happen from an allocation like kcalloc.

> 
> There are two ways to fix this issue.
> 
> [1] Make it a double-pointer
>   struct clk_hw_onecell_data {
>           size_t num;
>           struct clk_hw **hws;
>   };
> 
> This works as struct clk_onecell_data does.

True we could go back to the old style with two allocations.

> 
> [2] Make it a zero-sized array
>   struct clk_hw_onecell_data {
>           size_t num;
>           struct clk_hw *hws[0];
>   };
> 
> This allows one-shot memory allocation like this:
> 
>   hw_data = kmalloc(sizeof(*hw_data) + clk_num * sizeof(struct clk_hw *),
>                     GFP_KERNEL);
> 

Good, that was possible before this patch wasn't it?

> This commit adopts [2] because it looks like Stephen's intention
> (he moved hws[] to the bottom of struct clk_hw_onecell_data).
> 
> Fixes: 0861e5b8cf80 ("clk: Add clk_hw OF clk providers")
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---

> 
>  include/linux/clk-provider.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index fd2ccd5..1850e25 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -769,7 +769,7 @@ struct clk_onecell_data {
>  
>  struct clk_hw_onecell_data {
>  	size_t num;
> -	struct clk_hw *hws[];
> +	struct clk_hw *hws[0];

I'm totally lost now. Isn't a flex array with [] or with [0] the
same? The latter being a GCC extension while the former being a
C99 standard?

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH] clk: fix member type of struct clk_hw_onecell_data
  2016-04-25 22:27 ` Stephen Boyd
@ 2016-04-26  6:19   ` Masahiro Yamada
  0 siblings, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2016-04-26  6:19 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: linux-clk, Michael Turquette, Linux Kernel Mailing List

Hi Stephen,


2016-04-26 7:27 GMT+09:00 Stephen Boyd <sboyd@codeaurora.org>:
> On 04/25, Masahiro Yamada wrote:
>> We cannot assign any value to an array type variable.  So,
>>
>>   hw_data->hws = kcalloc(hw_data->num, sizeof(struct clk_hw *),
>>                          GFP_KERNEL);
>>
>> fails with "invalid use of flexible array member" error.
>
> That's good. We don't want assignment to the hws member of this
> structure to happen from an allocation like kcalloc.
>
>>
>> There are two ways to fix this issue.
>>
>> [1] Make it a double-pointer
>>   struct clk_hw_onecell_data {
>>           size_t num;
>>           struct clk_hw **hws;
>>   };
>>
>> This works as struct clk_onecell_data does.
>
> True we could go back to the old style with two allocations.
>
>>
>> [2] Make it a zero-sized array
>>   struct clk_hw_onecell_data {
>>           size_t num;
>>           struct clk_hw *hws[0];
>>   };
>>
>> This allows one-shot memory allocation like this:
>>
>>   hw_data = kmalloc(sizeof(*hw_data) + clk_num * sizeof(struct clk_hw *),
>>                     GFP_KERNEL);
>>
>
> Good, that was possible before this patch wasn't it?
>
>> This commit adopts [2] because it looks like Stephen's intention
>> (he moved hws[] to the bottom of struct clk_hw_onecell_data).
>>
>> Fixes: 0861e5b8cf80 ("clk: Add clk_hw OF clk providers")
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> ---
>
>>
>>  include/linux/clk-provider.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
>> index fd2ccd5..1850e25 100644
>> --- a/include/linux/clk-provider.h
>> +++ b/include/linux/clk-provider.h
>> @@ -769,7 +769,7 @@ struct clk_onecell_data {
>>
>>  struct clk_hw_onecell_data {
>>       size_t num;
>> -     struct clk_hw *hws[];
>> +     struct clk_hw *hws[0];
>
> I'm totally lost now. Isn't a flex array with [] or with [0] the
> same?

I was misunderstanding.

You are right.  They are the same.


> The latter being a GCC extension while the former being a
> C99 standard?


Please ignore this patch.  Sorry for noise.




-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2016-04-26  6:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-25  2:50 [PATCH] clk: fix member type of struct clk_hw_onecell_data Masahiro Yamada
2016-04-25 22:27 ` Stephen Boyd
2016-04-26  6:19   ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox