Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] clk: sunxi-ng: v3s: Fix incorrect number of hw_clks.
@ 2019-11-09 15:19 Tian Yunhao
  2019-11-11 12:39 ` Maxime Ripard
  0 siblings, 1 reply; 4+ messages in thread
From: Tian Yunhao @ 2019-11-09 15:19 UTC (permalink / raw)
  Cc: tian yunhao, Stephen Boyd, Michael Turquette, linux-kernel,
	Maxime Ripard, Chen-Yu Tsai, linux-clk, linux-arm-kernel,
	Icenowy Zheng

The hws field of sun8i_v3s_hw_clks has only 74
members. However, the number specified by CLK_NUMBER
is 77 (= CLK_I2S0 + 1). This leads to runtime segmentation
fault that is not always reproducible.

This patch adds a protective field [CLK_NUMBER] which ensures
ARRAY_SIZE(.hws) is always greater than .num, thus eliminates
this error.

Signed-off-by: Yunhao Tian <t123yh@outlook.com>
---
 drivers/clk/sunxi-ng/ccu-sun8i-v3s.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
index 5c779eec454b..de7fce7f32e6 100644
--- a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
+++ b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
@@ -617,6 +617,7 @@ static struct clk_hw_onecell_data sun8i_v3s_hw_clks = {
 		[CLK_AVS]		= &avs_clk.common.hw,
 		[CLK_MBUS]		= &mbus_clk.common.hw,
 		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
+		[CLK_NUMBER]    = NULL,
 	},
 	.num	= CLK_NUMBER,
 };
@@ -699,6 +700,7 @@ static struct clk_hw_onecell_data sun8i_v3_hw_clks = {
 		[CLK_AVS]		= &avs_clk.common.hw,
 		[CLK_MBUS]		= &mbus_clk.common.hw,
 		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
+		[CLK_NUMBER]    = NULL,
 	},
 	.num	= CLK_NUMBER,
 };
-- 
2.23.0


_______________________________________________
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] clk: sunxi-ng: v3s: Fix incorrect number of hw_clks.
  2019-11-09 15:19 [PATCH] clk: sunxi-ng: v3s: Fix incorrect number of hw_clks Tian Yunhao
@ 2019-11-11 12:39 ` Maxime Ripard
  2019-11-12 12:59   ` Icenowy Zheng
  0 siblings, 1 reply; 4+ messages in thread
From: Maxime Ripard @ 2019-11-11 12:39 UTC (permalink / raw)
  To: Tian Yunhao
  Cc: Stephen Boyd, Michael Turquette, linux-kernel, Chen-Yu Tsai,
	linux-clk, linux-arm-kernel, Icenowy Zheng

[-- Attachment #1.1: Type: text/plain, Size: 1408 bytes --]

Hi,

Thanks for your patch

On Sat, Nov 09, 2019 at 03:19:09PM +0000, Tian Yunhao wrote:
> The hws field of sun8i_v3s_hw_clks has only 74
> members. However, the number specified by CLK_NUMBER
> is 77 (= CLK_I2S0 + 1). This leads to runtime segmentation
> fault that is not always reproducible.
>
> This patch adds a protective field [CLK_NUMBER] which ensures
> ARRAY_SIZE(.hws) is always greater than .num, thus eliminates
> this error.
>
> Signed-off-by: Yunhao Tian <t123yh@outlook.com>
> ---
>  drivers/clk/sunxi-ng/ccu-sun8i-v3s.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
> index 5c779eec454b..de7fce7f32e6 100644
> --- a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
> +++ b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
> @@ -617,6 +617,7 @@ static struct clk_hw_onecell_data sun8i_v3s_hw_clks = {
>  		[CLK_AVS]		= &avs_clk.common.hw,
>  		[CLK_MBUS]		= &mbus_clk.common.hw,
>  		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
> +		[CLK_NUMBER]    = NULL,
>  	},
>  	.num	= CLK_NUMBER,
>  };
> @@ -699,6 +700,7 @@ static struct clk_hw_onecell_data sun8i_v3_hw_clks = {
>  		[CLK_AVS]		= &avs_clk.common.hw,
>  		[CLK_MBUS]		= &mbus_clk.common.hw,
>  		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
> +		[CLK_NUMBER]    = NULL,
>  	},
>  	.num	= CLK_NUMBER,

I'd rather have the number of clocks (.num) being properly set.

Maxime

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
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] clk: sunxi-ng: v3s: Fix incorrect number of hw_clks.
  2019-11-11 12:39 ` Maxime Ripard
@ 2019-11-12 12:59   ` Icenowy Zheng
  2019-11-12 19:16     ` Maxime Ripard
  0 siblings, 1 reply; 4+ messages in thread
From: Icenowy Zheng @ 2019-11-12 12:59 UTC (permalink / raw)
  To: linux-arm-kernel, Maxime Ripard, Tian Yunhao
  Cc: Stephen Boyd, Michael Turquette, linux-kernel, Chen-Yu Tsai,
	linux-clk, linux-arm-kernel



于 2019年11月11日 GMT+08:00 下午8:39:36, Maxime Ripard <mripard@kernel.org> 写到:
>Hi,
>
>Thanks for your patch
>
>On Sat, Nov 09, 2019 at 03:19:09PM +0000, Tian Yunhao wrote:
>> The hws field of sun8i_v3s_hw_clks has only 74
>> members. However, the number specified by CLK_NUMBER
>> is 77 (= CLK_I2S0 + 1). This leads to runtime segmentation
>> fault that is not always reproducible.
>>
>> This patch adds a protective field [CLK_NUMBER] which ensures
>> ARRAY_SIZE(.hws) is always greater than .num, thus eliminates
>> this error.
>>
>> Signed-off-by: Yunhao Tian <t123yh@outlook.com>
>> ---
>>  drivers/clk/sunxi-ng/ccu-sun8i-v3s.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
>b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
>> index 5c779eec454b..de7fce7f32e6 100644
>> --- a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
>> +++ b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
>> @@ -617,6 +617,7 @@ static struct clk_hw_onecell_data
>sun8i_v3s_hw_clks = {
>>  		[CLK_AVS]		= &avs_clk.common.hw,
>>  		[CLK_MBUS]		= &mbus_clk.common.hw,
>>  		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
>> +		[CLK_NUMBER]    = NULL,
>>  	},
>>  	.num	= CLK_NUMBER,
>>  };
>> @@ -699,6 +700,7 @@ static struct clk_hw_onecell_data
>sun8i_v3_hw_clks = {
>>  		[CLK_AVS]		= &avs_clk.common.hw,
>>  		[CLK_MBUS]		= &mbus_clk.common.hw,
>>  		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
>> +		[CLK_NUMBER]    = NULL,
>>  	},
>>  	.num	= CLK_NUMBER,
>
>I'd rather have the number of clocks (.num) being properly set.

However the maximum clock indices number is different on V3s and V3, because
on V3s the last clock is missing.

Should we define CLK_NUMBER_V3S here?

>
>Maxime

_______________________________________________
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] clk: sunxi-ng: v3s: Fix incorrect number of hw_clks.
  2019-11-12 12:59   ` Icenowy Zheng
@ 2019-11-12 19:16     ` Maxime Ripard
  0 siblings, 0 replies; 4+ messages in thread
From: Maxime Ripard @ 2019-11-12 19:16 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: Tian Yunhao, Stephen Boyd, Michael Turquette, linux-kernel,
	Chen-Yu Tsai, linux-clk, linux-arm-kernel

[-- Attachment #1.1: Type: text/plain, Size: 2000 bytes --]

On Tue, Nov 12, 2019 at 08:59:56PM +0800, Icenowy Zheng wrote:
>
>
> 于 2019年11月11日 GMT+08:00 下午8:39:36, Maxime Ripard <mripard@kernel.org> 写到:
> >Hi,
> >
> >Thanks for your patch
> >
> >On Sat, Nov 09, 2019 at 03:19:09PM +0000, Tian Yunhao wrote:
> >> The hws field of sun8i_v3s_hw_clks has only 74
> >> members. However, the number specified by CLK_NUMBER
> >> is 77 (= CLK_I2S0 + 1). This leads to runtime segmentation
> >> fault that is not always reproducible.
> >>
> >> This patch adds a protective field [CLK_NUMBER] which ensures
> >> ARRAY_SIZE(.hws) is always greater than .num, thus eliminates
> >> this error.
> >>
> >> Signed-off-by: Yunhao Tian <t123yh@outlook.com>
> >> ---
> >>  drivers/clk/sunxi-ng/ccu-sun8i-v3s.c | 2 ++
> >>  1 file changed, 2 insertions(+)
> >>
> >> diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
> >b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
> >> index 5c779eec454b..de7fce7f32e6 100644
> >> --- a/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
> >> +++ b/drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
> >> @@ -617,6 +617,7 @@ static struct clk_hw_onecell_data
> >sun8i_v3s_hw_clks = {
> >>  		[CLK_AVS]		= &avs_clk.common.hw,
> >>  		[CLK_MBUS]		= &mbus_clk.common.hw,
> >>  		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
> >> +		[CLK_NUMBER]    = NULL,
> >>  	},
> >>  	.num	= CLK_NUMBER,
> >>  };
> >> @@ -699,6 +700,7 @@ static struct clk_hw_onecell_data
> >sun8i_v3_hw_clks = {
> >>  		[CLK_AVS]		= &avs_clk.common.hw,
> >>  		[CLK_MBUS]		= &mbus_clk.common.hw,
> >>  		[CLK_MIPI_CSI]		= &mipi_csi_clk.common.hw,
> >> +		[CLK_NUMBER]    = NULL,
> >>  	},
> >>  	.num	= CLK_NUMBER,
> >
> >I'd rather have the number of clocks (.num) being properly set.
>
> However the maximum clock indices number is different on V3s and V3, because
> on V3s the last clock is missing.
>
> Should we define CLK_NUMBER_V3S here?

That, or we can just reference the last clock, we're not using
CLK_NUMBER anywhere else.

Maxime

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
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, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-09 15:19 [PATCH] clk: sunxi-ng: v3s: Fix incorrect number of hw_clks Tian Yunhao
2019-11-11 12:39 ` Maxime Ripard
2019-11-12 12:59   ` Icenowy Zheng
2019-11-12 19:16     ` Maxime Ripard

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git