<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/clk/socfpga, branch v6.6.148</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.148</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.148'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2023-11-28T17:20:00+00:00</updated>
<entry>
<title>clk: socfpga: Fix undefined behavior bug in struct stratix10_clock_data</title>
<updated>2023-11-28T17:20:00+00:00</updated>
<author>
<name>Gustavo A. R. Silva</name>
<email>gustavoars@kernel.org</email>
</author>
<published>2023-10-24T03:30:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b0a660d46d40ad122d200cfdfbdba81a6346f4cb'/>
<id>urn:sha1:b0a660d46d40ad122d200cfdfbdba81a6346f4cb</id>
<content type='text'>
commit d761bb01c85b22d5b44abe283eb89019693f6595 upstream.

`struct clk_hw_onecell_data` is a flexible structure, which means that
it contains flexible-array member at the bottom, in this case array
`hws`:

include/linux/clk-provider.h:
1380 struct clk_hw_onecell_data {
1381         unsigned int num;
1382         struct clk_hw *hws[] __counted_by(num);
1383 };

This could potentially lead to an overwrite of the objects following
`clk_data` in `struct stratix10_clock_data`, in this case
`void __iomem *base;` at run-time:

drivers/clk/socfpga/stratix10-clk.h:
  9 struct stratix10_clock_data {
 10         struct clk_hw_onecell_data      clk_data;
 11         void __iomem            *base;
 12 };

There are currently three different places where memory is allocated for
`struct stratix10_clock_data`, including the flex-array `hws` in
`struct clk_hw_onecell_data`:

drivers/clk/socfpga/clk-agilex.c:
469         clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws,
470                                 num_clks), GFP_KERNEL);

drivers/clk/socfpga/clk-agilex.c:
509         clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws,
510                                 num_clks), GFP_KERNEL);

drivers/clk/socfpga/clk-s10.c:
400         clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws,
401                                                  num_clks), GFP_KERNEL);

I'll use just one of them to describe the issue. See below.

Notice that a total of 440 bytes are allocated for flexible-array member
`hws` at line 469:

include/dt-bindings/clock/agilex-clock.h:
 70 #define AGILEX_NUM_CLKS	55

drivers/clk/socfpga/clk-agilex.c:
459         struct stratix10_clock_data *clk_data;
460         void __iomem *base;
...
466
467         num_clks = AGILEX_NUM_CLKS;
468
469         clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws,
470                                 num_clks), GFP_KERNEL);

`struct_size(clk_data, clk_data.hws, num_clks)`	above translates to
sizeof(struct stratix10_clock_data) + sizeof(struct clk_hw *) * 55 ==
16 + 8 * 55 == 16 + 440
		    ^^^
		     |
	allocated bytes for flex-array `hws`

474         for (i = 0; i &lt; num_clks; i++)
475                 clk_data-&gt;clk_data.hws[i] = ERR_PTR(-ENOENT);
476
477         clk_data-&gt;base = base;

and then some data is written into both `hws` and `base` objects.

Fix this by placing the declaration of object `clk_data` at the end of
`struct stratix10_clock_data`. Also, add a comment to make it clear
that this object must always be last in the structure.

-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.

Fixes: ba7e258425ac ("clk: socfpga: Convert to s10/agilex/n5x to use clk_hw")
Cc: stable@vger.kernel.org
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Signed-off-by: Gustavo A. R. Silva &lt;gustavoars@kernel.org&gt;
Link: https://lore.kernel.org/r/1da736106d8e0806aeafa6e471a13ced490eae22.1698117815.git.gustavoars@kernel.org
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: gate: Account for the divider in determine_rate</title>
<updated>2023-10-13T00:30:54+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>mripard@kernel.org</email>
</author>
<published>2023-10-12T08:37:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=601cb6d573facde5fc88efa935b074da64ae63c9'/>
<id>urn:sha1:601cb6d573facde5fc88efa935b074da64ae63c9</id>
<content type='text'>
Commit 9607beb917df ("clk: socfpga: gate: Add a determine_rate hook")
added a determine_rate implementation set to the
clk_hw_determine_rate_no_reparent, but failed to account for the
internal divider that wasn't used before anywhere but in recalc_rate.

This led to inconsistencies between the clock rate stored in
clk_core-&gt;rate and the one returned by clk_round_rate() that leverages
determine_rate().

Since that driver seems to be widely used (and thus regression-prone)
and not supporting rate changes (since it's missing a .set_rate
implementation), we can just report the current divider programmed in
the clock but not try to change it in any way.

This should be good enough to fix the issues reported, and if someone
ever wants to allow the divider to change then it should be easy enough
using the clk-divider helpers.

Link: https://lore.kernel.org/linux-clk/20231005095927.12398-2-b.spranger@linutronix.de/
Fixes: 9607beb917df ("clk: socfpga: gate: Add a determine_rate hook")
Reported-by: Benedikt Spranger &lt;b.spranger@linutronix.de&gt;
Signed-off-by: Maxime Ripard &lt;mripard@kernel.org&gt;
Link: https://lore.kernel.org/r/20231012083729.2148044-1-mripard@kernel.org
[sboyd@kernel.org: Fix hw -&gt; hwclk]
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: agilex: Convert to devm_platform_ioremap_resource()</title>
<updated>2023-08-22T21:28:34+00:00</updated>
<author>
<name>Yangtao Li</name>
<email>frank.li@vivo.com</email>
</author>
<published>2023-07-05T06:53:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=90f79ac5bf67ce5a347a0c5fe2b2d87618c306a9'/>
<id>urn:sha1:90f79ac5bf67ce5a347a0c5fe2b2d87618c306a9</id>
<content type='text'>
Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li &lt;frank.li@vivo.com&gt;
Link: https://lore.kernel.org/r/20230705065313.67043-11-frank.li@vivo.com
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: Explicitly include correct DT includes</title>
<updated>2023-07-19T20:13:16+00:00</updated>
<author>
<name>Rob Herring</name>
<email>robh@kernel.org</email>
</author>
<published>2023-07-18T14:31:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a96cbb146a9736f501fe66ebda6a9018735e5e8a'/>
<id>urn:sha1:a96cbb146a9736f501fe66ebda6a9018735e5e8a</id>
<content type='text'>
The DT of_device.h and of_platform.h date back to the separate
of_platform_bus_type before it as merged into the regular platform bus.
As part of that merge prepping Arm DT support 13 years ago, they
"temporarily" include each other. They also include platform_device.h
and of.h. As a result, there's a pretty much random mix of those include
files used throughout the tree. In order to detangle these headers and
replace the implicit includes with struct declarations, users need to
explicitly include the correct includes.

Acked-by: Dinh Nguyen &lt;dinguyen@kernel.org&gt;
Acked-by: Krzysztof Kozlowski &lt;krzysztof.kozlowski@linaro.org&gt; # samsung
Acked-by: Heiko Stuebner &lt;heiko@sntech.de&gt; #rockchip
Acked-by: Chanwoo Choi &lt;cw00.choi@samsung.com&gt;
Acked-by: Geert Uytterhoeven &lt;geert+renesas@glider.be&gt;
Reviewed-by: AngeloGioacchino Del Regno &lt;angelogioacchino.delregno@collabora.com&gt;
Reviewed-by: Luca Ceresoli &lt;luca.ceresoli@bootlin.com&gt; # versaclock5
Signed-off-by: Rob Herring &lt;robh@kernel.org&gt;
Link: https://lore.kernel.org/r/20230718143156.1066339-1-robh@kernel.org
Acked-by: Abel Vesa &lt;abel.vesa@linaro.org&gt; #imx
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: gate: Add a determine_rate hook</title>
<updated>2023-06-09T01:39:29+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2023-05-05T11:25:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=9607beb917df80ce70e8d46b733eae25f7ba582a'/>
<id>urn:sha1:9607beb917df80ce70e8d46b733eae25f7ba582a</id>
<content type='text'>
The SoCFGPA gate clock implements a mux with a set_parent hook, but
doesn't provide a determine_rate implementation.

This is a bit odd, since set_parent() is there to, as its name implies,
change the parent of a clock. However, the most likely candidates to
trigger that parent change are either the assigned-clock-parents device
tree property or a call to clk_set_rate(), with determine_rate()
figuring out which parent is the best suited for a given rate.

The other trigger would be a call to clk_set_parent(), but it's far less
used, and it doesn't look like there's any obvious user for that clock.

Similarly, it doesn't look like the device tree using that clock driver
uses any of the assigned-clock properties on that clock.

So, the set_parent hook is effectively unused, possibly because of an
oversight. However, it could also be an explicit decision by the
original author to avoid any reparenting but through an explicit call to
clk_set_parent().

The latter case would be equivalent to setting the determine_rate
implementation to clk_hw_determine_rate_no_reparent(). Indeed, if no
determine_rate implementation is provided, clk_round_rate() (through
clk_core_round_rate_nolock()) will call itself on the parent if
CLK_SET_RATE_PARENT is set, and will not change the clock rate
otherwise.

And if it was an oversight, then we are at least explicit about our
behavior now and it can be further refined down the line.

Cc: Dinh Nguyen &lt;dinguyen@kernel.org&gt;
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-32-971d5077e7d2@cerno.tech
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: arria10: use of_clk_add_hw_provider and improve error handling</title>
<updated>2023-03-21T23:47:48+00:00</updated>
<author>
<name>Marco Pagani</name>
<email>marpagan@redhat.com</email>
</author>
<published>2022-12-09T15:29:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3dc6faa3ab0260c1d2058d45f0a93928f917348a'/>
<id>urn:sha1:3dc6faa3ab0260c1d2058d45f0a93928f917348a</id>
<content type='text'>
The function of_clk_add_provider() has been deprecated, so use its
suggested replacement of_clk_add_hw_provider() instead.

Since of_clk_add_hw_provider() can fail, like of_clk_add_provider(),
check its return value and do the error handling.

The return type of the init function has been changed to void since
the return value was not used, and the indentation of the parameters has
been aligned to match open parenthesis, as suggested by checkpatch.

Signed-off-by: Marco Pagani &lt;marpagan@redhat.com&gt;
Link: https://lore.kernel.org/r/20221209152913.1335068-7-marpagan@redhat.com
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: use of_clk_add_hw_provider and improve error handling</title>
<updated>2023-03-21T23:47:48+00:00</updated>
<author>
<name>Marco Pagani</name>
<email>marpagan@redhat.com</email>
</author>
<published>2022-12-09T15:29:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=00720a904877bb7e5f16e5ca409391bdd64ea5c4'/>
<id>urn:sha1:00720a904877bb7e5f16e5ca409391bdd64ea5c4</id>
<content type='text'>
The function of_clk_add_provider() has been deprecated, so use its
suggested replacement of_clk_add_hw_provider() instead.

Since of_clk_add_hw_provider() can fail, like of_clk_add_provider(),
check its return value and do the error handling.

The return type of the init function has been changed to void since
the return value was not used, and the indentation of the parameters has
been aligned to match open parenthesis, as suggested by checkpatch.

The err variable has been renamed rc for consistency.

Signed-off-by: Marco Pagani &lt;marpagan@redhat.com&gt;
Link: https://lore.kernel.org/r/20221209152913.1335068-6-marpagan@redhat.com
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: arria10: use of_clk_add_hw_provider and improve error handling</title>
<updated>2023-03-21T23:47:48+00:00</updated>
<author>
<name>Marco Pagani</name>
<email>marpagan@redhat.com</email>
</author>
<published>2022-12-09T15:29:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6e83bd71c0cf196b52e3cb69c26b0cc579fe4c6c'/>
<id>urn:sha1:6e83bd71c0cf196b52e3cb69c26b0cc579fe4c6c</id>
<content type='text'>
The function of_clk_add_provider() has been deprecated, so use its
suggested replacement of_clk_add_hw_provider() instead.

Since of_clk_add_hw_provider() can fail, like of_clk_add_provider(),
check its return value and do the error handling.

The indentation of the init function parameters has been aligned
to match open parenthesis as suggested by checkpatch.

Signed-off-by: Marco Pagani &lt;marpagan@redhat.com&gt;
Link: https://lore.kernel.org/r/20221209152913.1335068-5-marpagan@redhat.com
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: use of_clk_add_hw_provider and improve error handling</title>
<updated>2023-03-21T23:47:48+00:00</updated>
<author>
<name>Marco Pagani</name>
<email>marpagan@redhat.com</email>
</author>
<published>2022-12-09T15:29:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=85f1b574059d88f4b7f5dc0401f3745b305476f9'/>
<id>urn:sha1:85f1b574059d88f4b7f5dc0401f3745b305476f9</id>
<content type='text'>
The function of_clk_add_provider() has been deprecated, so use its
suggested replacement of_clk_add_hw_provider() instead.

Since of_clk_add_hw_provider() can fail, like of_clk_add_provider(),
check its return value and do the error handling.

The err variable unnecessarily duplicates the functionality of the
rc variable, so it has been removed.

Signed-off-by: Marco Pagani &lt;marpagan@redhat.com&gt;
Link: https://lore.kernel.org/r/20221209152913.1335068-4-marpagan@redhat.com
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: socfpga: arria10: use of_clk_add_hw_provider and improve error handling</title>
<updated>2023-03-21T23:47:48+00:00</updated>
<author>
<name>Marco Pagani</name>
<email>marpagan@redhat.com</email>
</author>
<published>2022-12-09T15:29:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=da939f6d8080ad12415240c584de03816fd575b8'/>
<id>urn:sha1:da939f6d8080ad12415240c584de03816fd575b8</id>
<content type='text'>
The function of_clk_add_provider() has been deprecated, so use its
suggested replacement of_clk_add_hw_provider() instead.

Since of_clk_add_hw_provider() can fail, like of_clk_add_provider(),
check its return value and do the error handling.

The indentation of the init function parameters has been aligned
to match open parenthesis, as suggested by checkpatch, and the __init
macro moved before the function name, as specified in init.h.

Signed-off-by: Marco Pagani &lt;marpagan@redhat.com&gt;
Link: https://lore.kernel.org/r/20221209152913.1335068-3-marpagan@redhat.com
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
</feed>
