of: Fix some 'const' problems
Subsystems (7)
cover of: Fix some 'const' problems
A cast is often needed to call some OF functions, removing the 'const' attribute.
This patchset makes 'const' the device node pointers of the functions of_clk_get() and of_node_put() and also removes some useless casts in the sound/soc tree.
Jean-Francois Moine (2):
of: Make const the device node pointers in of_clk_get and of_node_put
ASoC: Remove useless casts
drivers/clk/clkdev.c | 2 +- drivers/of/dynamic.c | 2 +- include/linux/clk.h | 4 ++-- include/linux/of.h | 4 ++-- sound/soc/generic/simple-card.c | 7 ++----- sound/soc/samsung/odroidx2_max98090.c | 4 ++-- sound/soc/ux500/mop500.c | 6 ++---- 7 files changed, 12 insertions(+), 17 deletions(-)
Signature · 1 line
2.1.3
PATCH 1/2 of: Make const the device node pointers in of_clk_get and of_node_put
Some device nodes are sometimes referenced by const pointers.
This patch avoids to cast these pointers when calling the functions of_clk_get() and of_node_put().
--- drivers/clk/clkdev.c | 2 +- drivers/of/dynamic.c | 2 +- include/linux/clk.h | 4 ++-- include/linux/of.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-)
drivers/clk/clkdev.c +1 -1
@@ -53,7 +53,7 @@ struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec)return clk; } -struct clk *of_clk_get (struct device_node *np,int index) +struct clk *of_clk_get (const struct device_node *np,int index) {struct of_phandle_args clkspec;struct clk *clk;
drivers/of/dynamic.c +1 -1
@@ -34,7 +34,7 @@ EXPORT_SYMBOL(of_node_get);* @node: Node to dec refcount, NULL is supported to simplify writing of * callers */ -void of_node_put (struct device_node *node) +void of_node_put (const struct device_node *node) {if (node)kobject_put (&node->kobj);
include/linux/clk.h +2 -2
@@ -425,11 +425,11 @@ struct device_node;struct of_phandle_args ;#if defined(CONFIG_OF ) && defined(CONFIG_COMMON_CLK ) -struct clk *of_clk_get (struct device_node *np,int index); +struct clk *of_clk_get (const struct device_node *np,int index);struct clk *of_clk_get_by_name (struct device_node *np,const char *name);struct clk *of_clk_get_from_provider (struct of_phandle_args *clkspec);#else -static inline struct clk *of_clk_get (struct device_node *np,int index) +static inline struct clk *of_clk_get (const struct device_node *np,int index) {return ERR_PTR (-ENOENT ); }
include/linux/of.h +2 -2
@@ -95,14 +95,14 @@ static inline int of_node_is_attached(struct device_node *node)#ifdef CONFIG_OF_DYNAMIC extern struct device_node *of_node_get (struct device_node *node); -extern void of_node_put (struct device_node *node); +extern void of_node_put (const struct device_node *node);#else /* CONFIG_OF_DYNAMIC */ /* Dummy ref counting routines - to be implemented later */ static inline struct device_node *of_node_get (struct device_node *node) {return node; } -static inline void of_node_put (struct device_node *node) { } +static inline void of_node_put (const struct device_node *node) { }#endif /* !CONFIG_OF_DYNAMIC */ #ifdef CONFIG_OF
Signature · 1 line
2.1.3
Re: [PATCH 1/2] of: Make const the device node pointers in of_clk_get and of_node_put
Quoted 4 lines · Jean-Francois Moine
Some device nodes are sometimes referenced by const pointers.
This patch avoids to cast these pointers when calling the functions
of_clk_get()andof_node_put().
NAK. Firstly, of_node_put contains a kref, which is /definitely/ not a const item when kobject_put() is called on it. Inside the kobject is a kref, which kobject_put() will call kref_put() on. kref_put() in turn will internally call atomic_sub_and_test() on a value embedded within the kref struct.
Ergo, of_node_put() modifies the struct device_node contents. Therefore, of_node_put() definitely not treating the data pointed to as read-only, and therefore it is completely inappropriate for it to be marked "const".
What this then means is that it fundamentally undermines the idea of storing the pointer to a device_node as a const pointer, as the device node must always be modified when you're done with it (because it's a ref-counted structure.) So, having it const in your code is a bug.
What this also means is that every other place that you've added const below is also very dubious.
Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up according to speedtest.net.
Re: [PATCH 1/2] of: Make const the device node pointers in of_clk_get and of_node_put
Quoted 7 lines · On Sun, 9 Nov 2014 18:50:19 +0000 Russell King - ARM Linux…
What this then means is that it fundamentally undermines the idea of storing the pointer to a
device_nodeas a const pointer, as the device node must always be modified when you're done with it (because it's a ref-counted structure.) So, having it const in your code is a bug.What this also means is that every other place that you've added const below is also very dubious.
Thanks for the explanation.
The correct patch will be simpler: in the ASoC structures, I found only three places where the device_node pointer is const.
Signature · 2 lines
Ken ar c'hentañ | ** Breizh ha Linux atav! ** Jef | http://moinejf.free.fr/
PATCH 2/2 ASoC: Remove useless casts
In reply to Jean-Francois MoineThere is no need to cast the cpu_of_node or codec_of_node of the dai_links when calling of_put_node.
--- sound/soc/generic/simple-card.c | 7 ++----- sound/soc/samsung/odroidx2_max98090.c | 4 ++-- sound/soc/ux500/mop500.c | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-)
sound/soc/generic/simple-card.c +2 -5
@@ -457,16 +457,13 @@ static int asoc_simple_card_unref(struct platform_device *pdev) {struct snd_soc_card *card =platform_get_drvdata (pdev);struct snd_soc_dai_link *dai_link; -struct device_node *np;int num_links;for (num_links =0 , dai_link = card->dai_link; num_links < card->num_links; num_links++, dai_link++) { - np = (struct device_node *) dai_link->cpu_of_node; -of_node_put (np); - np = (struct device_node *) dai_link->codec_of_node; -of_node_put (np); +of_node_put (dai_link->cpu_of_node); +of_node_put (dai_link->codec_of_node); }return 0 ; }
sound/soc/samsung/odroidx2_max98090.c +2 -2
@@ -153,8 +153,8 @@ static int odroidx2_audio_remove(struct platform_device *pdev)snd_soc_unregister_card (card); -of_node_put ((struct device_node *)odroidx2_dai[0 ].cpu_of_node); -of_node_put ((struct device_node *)odroidx2_dai[0 ].codec_of_node); +of_node_put (odroidx2_dai[0 ].cpu_of_node); +of_node_put (odroidx2_dai[0 ].codec_of_node);return 0 ; }
sound/soc/ux500/mop500.c +2 -4
@@ -64,11 +64,9 @@ static void mop500_of_node_put(void)for (i =0 ; i <2 ; i++) {if (mop500_dai_links[i].cpu_of_node) -of_node_put ((struct device_node *) - mop500_dai_links[i].cpu_of_node); +of_node_put (mop500_dai_links[i].cpu_of_node);if (mop500_dai_links[i].codec_of_node) -of_node_put ((struct device_node *) - mop500_dai_links[i].codec_of_node); +of_node_put (mop500_dai_links[i].codec_of_node); } }
Signature · 1 line
2.1.3