linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: core: Copy connection id
@ 2017-02-20 13:20 Leonard Crestez
  2017-02-24 20:44 ` Stephen Boyd
  0 siblings, 1 reply; 6+ messages in thread
From: Leonard Crestez @ 2017-02-20 13:20 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, linux-clk; +Cc: Leonard Crestez, linux-kernel

Some drivers use sprintf to build clk connection id names but the clk
core will save those strings and occasionally print them back. Duplicate
the con_id strings instead of fixing all the users.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
---
 drivers/clk/clk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Some examples of using sprintf for con_id include:
drivers/mfd/omap-usb-host.c
drivers/tty/serial/samsung.c
sound/soc/fsl/fsl_asrc.c

There are lots more. They are difficult to find and "fixing" them on the
consumer side requires nasty code to keep track of the allocated clkname.

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 0fb39fe..67201f6 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2502,7 +2502,7 @@ struct clk *__clk_create_clk(struct clk_hw *hw, const char *dev_id,
 
 	clk->core = hw->core;
 	clk->dev_id = dev_id;
-	clk->con_id = con_id;
+	clk->con_id = kstrdup_const(con_id, GFP_KERNEL);
 	clk->max_rate = ULONG_MAX;
 
 	clk_prepare_lock();
@@ -2518,6 +2518,7 @@ void __clk_free_clk(struct clk *clk)
 	hlist_del(&clk->clks_node);
 	clk_prepare_unlock();
 
+	kfree_const(clk->con_id);
 	kfree(clk);
 }
 
-- 
2.7.4

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

* Re: [PATCH] clk: core: Copy connection id
  2017-02-20 13:20 [PATCH] clk: core: Copy connection id Leonard Crestez
@ 2017-02-24 20:44 ` Stephen Boyd
  2017-02-25  9:20   ` Leonard Crestez
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2017-02-24 20:44 UTC (permalink / raw)
  To: Leonard Crestez; +Cc: Michael Turquette, linux-clk, linux-kernel

On 02/20, Leonard Crestez wrote:
> Some drivers use sprintf to build clk connection id names but the clk
> core will save those strings and occasionally print them back. Duplicate
> the con_id strings instead of fixing all the users.
> 
> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
> ---
>  drivers/clk/clk.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> Some examples of using sprintf for con_id include:
> drivers/mfd/omap-usb-host.c
> drivers/tty/serial/samsung.c
> sound/soc/fsl/fsl_asrc.c
> 
> There are lots more. They are difficult to find and "fixing" them on the
> consumer side requires nasty code to keep track of the allocated clkname.

Good catch. What about dev_id though? That could also have the
same problem if some device is removed and we're still holding a
reference to the kobject's name. This is probably more rare than
what is happening here, but still seems possible that we might
trip over that later.

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

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

* Re: [PATCH] clk: core: Copy connection id
  2017-02-24 20:44 ` Stephen Boyd
@ 2017-02-25  9:20   ` Leonard Crestez
  2017-02-28  8:05     ` sboyd
  0 siblings, 1 reply; 6+ messages in thread
From: Leonard Crestez @ 2017-02-25  9:20 UTC (permalink / raw)
  To: sboyd@codeaurora.org
  Cc: linux-kernel@vger.kernel.org, mturquette@baylibre.com,
	linux-clk@vger.kernel.org

T24gRnJpLCAyMDE3LTAyLTI0IGF0IDEyOjQ0IC0wODAwLCBTdGVwaGVuIEJveWQgd3JvdGU6DQo+
IE9uIDAyLzIwLCBMZW9uYXJkIENyZXN0ZXogd3JvdGU6DQo+ID4gU29tZSBkcml2ZXJzIHVzZSBz
cHJpbnRmIHRvIGJ1aWxkIGNsayBjb25uZWN0aW9uIGlkIG5hbWVzIGJ1dCB0aGUNCj4gPiBjbGsN
Cj4gPiBjb3JlIHdpbGwgc2F2ZSB0aG9zZSBzdHJpbmdzIGFuZCBvY2Nhc2lvbmFsbHkgcHJpbnQg
dGhlbSBiYWNrLg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 2017-02-28  8:05     ` sboyd
  2017-03-02 12:45       ` Leonard Crestez
  0 siblings, 1 reply; 6+ messages in thread
From: sboyd @ 2017-02-28  8:05 UTC (permalink / raw)
  To: Leonard Crestez
  Cc: linux-kernel@vger.kernel.org, mturquette@baylibre.com,
	linux-clk@vger.kernel.org

On 02/25, Leonard Crestez wrote:
> On Fri, 2017-02-24 at 12:44 -0800, Stephen Boyd wrote:
> > On 02/20, Leonard Crestez wrote:
> > > Some drivers use sprintf to build clk connection id names but the
> > > clk
> > > core will save those strings and occasionally print them back.
> > > Duplicate
> > > the con_id strings instead of fixing all the users.
> > 
> > Good catch. What about dev_id though? That could also have the
> > same problem if some device is removed and we're still holding a
> > reference to the kobject's name. This is probably more rare than
> > what is happening here, but still seems possible that we might
> > trip over that later.
> 
> A device should normally free the clks it uses before it is destroyed.
> This means that if dev_id is pointing to freed memory then the clk
> itself was probably leaked, right?

Sure. clk_get_sys() could be called and then we could have
something sprintf the dev_id there. A quick grep doesn't show any
place where that happens though so it seems safe right now.

That said, it would be nice to clearly document that we don't
expect dev_id to be freed or changed during the lifetime of the
clk structure, but we do allow con_id to change. Perhaps the copy
shows that, but a comment would also be useful so we don't have
people wondering why dev_id isn't copied as well.

> 
> This is obvious misuse of the API, not like sprintf-ing a con_id in a
> complex driver. I don't really think it's worth copying strings for it.
> 

Ok.

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

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

* Re: [PATCH] clk: core: Copy connection id
  2017-02-28  8:05     ` sboyd
@ 2017-03-02 12:45       ` Leonard Crestez
  2017-03-07 13:53         ` sboyd
  0 siblings, 1 reply; 6+ messages in thread
From: Leonard Crestez @ 2017-03-02 12:45 UTC (permalink / raw)
  To: sboyd@codeaurora.org
  Cc: linux-kernel@vger.kernel.org, mturquette@baylibre.com,
	linux-clk@vger.kernel.org

T24gVHVlLCAyMDE3LTAyLTI4IGF0IDAwOjA1IC0wODA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fZ2V0IGFuZCBkZXZtX2Nsa19nZXQs
IHJpZ2h0PyBUaGVzZSBzZWVtIHRvIGJlIHRoZSBwdWJsaWMgZW50cnkNCnBvaW50cyB0byB0aGUg
Y2xrIHN1YnN5c3RlbSBhbmQgdXNlcnMgYXJlIGV4cGVjdGVkIHRvIHJlYWQgdGhlaXIgZG9jcy4N
Cg0KRG8geW91IHdhbnQgbWUgdG8gcmVzZW5kIHRoZSBwYXRjaCB3aXRoIHRoZXNlIG5vdGVzPw0K
DQpJJ20gbm90IGNvbWZvcnRhYmxlIGFkZGluZyB0byBkb2N1bWVudGF0aW9uIHdoZW4gSSBkb24n
dCBmdWxseQ0KdW5kZXJzdGFuZCB0aGUgc3lzdGVtIG15c2VsZi4gSSBvbmx5IGRpc2NvdmVyZWQg
dGhpcyB3aGlsZSBsb29raW5nIGludG8NCnVucmVsYXRlZCBkcml2ZXIgaXNzdWVzLg==

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

* Re: [PATCH] clk: core: Copy connection id
  2017-03-02 12:45       ` Leonard Crestez
@ 2017-03-07 13:53         ` sboyd
  0 siblings, 0 replies; 6+ messages in thread
From: sboyd @ 2017-03-07 13:53 UTC (permalink / raw)
  To: Leonard Crestez
  Cc: linux-kernel@vger.kernel.org, mturquette@baylibre.com,
	linux-clk@vger.kernel.org

On 03/02, Leonard Crestez wrote:
> On Tue, 2017-02-28 at 00:05 -0800, sboyd@codeaurora.org wrote:
> > Sure. clk_get_sys() could be called and then we could have
> > something sprintf the dev_id there. A quick grep doesn't show any
> > place where that happens though so it seems safe right now.
> > 
> > That said, it would be nice to clearly document that we don't
> > expect dev_id to be freed or changed during the lifetime of the
> > clk structure, but we do allow con_id to change. Perhaps the copy
> > shows that, but a comment would also be useful so we don't have
> > people wondering why dev_id isn't copied as well.
> 
> This should be mentioned on the public documentation for clk_get_sys,
> clk_get and devm_clk_get, right? These seem to be the public entry
> points to the clk subsystem and users are expected to read their docs.

Sure. Except those are not just implemented for the common clk
framework, so the wording will need to be generic. Also we have
some more entry points like of_clk_get() too that would need a
note.

> 
> Do you want me to resend the patch with these notes?

No. I've applied this current patch to clk-fixes.

> 
> I'm not comfortable adding to documentation when I don't fully
> understand the system myself. I only discovered this while looking into
> unrelated driver issues.

Ok. I can take care of sending the patch.

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

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

end of thread, other threads:[~2017-03-07 13:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-20 13:20 [PATCH] clk: core: Copy connection id Leonard Crestez
2017-02-24 20:44 ` Stephen Boyd
2017-02-25  9:20   ` Leonard Crestez
2017-02-28  8:05     ` sboyd
2017-03-02 12:45       ` Leonard Crestez
2017-03-07 13:53         ` sboyd

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