linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure
@ 2015-11-25 12:52 LABBE Corentin
  2015-11-25 12:52 ` [PATCH 2/2] clk: palmas: fix a possible NULL dereference LABBE Corentin
  2016-01-30  0:57 ` [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: LABBE Corentin @ 2015-11-25 12:52 UTC (permalink / raw)
  To: mturquette, sboyd; +Cc: LABBE Corentin, linux-clk, linux-kernel

The palmas_clks_of_match_data structures are never modified.
This patch constify them.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
---
 drivers/clk/clk-palmas.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-palmas.c b/drivers/clk/clk-palmas.c
index 8e3039f..c55e774 100644
--- a/drivers/clk/clk-palmas.c
+++ b/drivers/clk/clk-palmas.c
@@ -44,7 +44,7 @@ struct palmas_clock_info {
 	struct clk *clk;
 	struct clk_hw hw;
 	struct palmas *palmas;
-	struct palmas_clk32k_desc *clk_desc;
+	const struct palmas_clk32k_desc *clk_desc;
 	int ext_control_pin;
 };
 
@@ -125,10 +125,10 @@ static struct clk_ops palmas_clks_ops = {
 
 struct palmas_clks_of_match_data {
 	struct clk_init_data init;
-	struct palmas_clk32k_desc desc;
+	const struct palmas_clk32k_desc desc;
 };
 
-static struct palmas_clks_of_match_data palmas_of_clk32kg = {
+static const struct palmas_clks_of_match_data palmas_of_clk32kg = {
 	.init = {
 		.name = "clk32kg",
 		.ops = &palmas_clks_ops,
@@ -144,7 +144,7 @@ static struct palmas_clks_of_match_data palmas_of_clk32kg = {
 	},
 };
 
-static struct palmas_clks_of_match_data palmas_of_clk32kgaudio = {
+static const struct palmas_clks_of_match_data palmas_of_clk32kgaudio = {
 	.init = {
 		.name = "clk32kgaudio",
 		.ops = &palmas_clks_ops,
@@ -240,14 +240,14 @@ static int palmas_clks_probe(struct platform_device *pdev)
 {
 	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
 	struct device_node *node = pdev->dev.of_node;
-	struct palmas_clks_of_match_data *match_data;
+	const struct palmas_clks_of_match_data *match_data;
 	const struct of_device_id *match;
 	struct palmas_clock_info *cinfo;
 	struct clk *clk;
 	int ret;
 
 	match = of_match_device(palmas_clks_of_match, &pdev->dev);
-	match_data = (struct palmas_clks_of_match_data *)match->data;
+	match_data = match->data;
 
 	cinfo = devm_kzalloc(&pdev->dev, sizeof(*cinfo), GFP_KERNEL);
 	if (!cinfo)
-- 
2.4.10


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

* [PATCH 2/2] clk: palmas: fix a possible NULL dereference
  2015-11-25 12:52 [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure LABBE Corentin
@ 2015-11-25 12:52 ` LABBE Corentin
  2016-01-30  0:58   ` Stephen Boyd
  2016-01-30  0:57 ` [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: LABBE Corentin @ 2015-11-25 12:52 UTC (permalink / raw)
  To: mturquette, sboyd; +Cc: LABBE Corentin, linux-clk, linux-kernel

of_match_device could return NULL, and so cause a NULL pointer
dereference later.
Even if the probability of this case is very low, fixing it made
static analyzers happy.

Solving this with of_device_get_match_data made also code simplier.

Reported-by: coverity (CID 1324137)
Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
---
 drivers/clk/clk-palmas.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-palmas.c b/drivers/clk/clk-palmas.c
index c55e774..9c0b8e6 100644
--- a/drivers/clk/clk-palmas.c
+++ b/drivers/clk/clk-palmas.c
@@ -241,13 +241,13 @@ static int palmas_clks_probe(struct platform_device *pdev)
 	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
 	struct device_node *node = pdev->dev.of_node;
 	const struct palmas_clks_of_match_data *match_data;
-	const struct of_device_id *match;
 	struct palmas_clock_info *cinfo;
 	struct clk *clk;
 	int ret;
 
-	match = of_match_device(palmas_clks_of_match, &pdev->dev);
-	match_data = match->data;
+	match_data = of_device_get_match_data(&pdev->dev);
+	if (!match_data)
+		return 1;
 
 	cinfo = devm_kzalloc(&pdev->dev, sizeof(*cinfo), GFP_KERNEL);
 	if (!cinfo)
-- 
2.4.10


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

* Re: [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure
  2015-11-25 12:52 [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure LABBE Corentin
  2015-11-25 12:52 ` [PATCH 2/2] clk: palmas: fix a possible NULL dereference LABBE Corentin
@ 2016-01-30  0:57 ` Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2016-01-30  0:57 UTC (permalink / raw)
  To: LABBE Corentin; +Cc: mturquette, linux-clk, linux-kernel

On 11/25, LABBE Corentin wrote:
> The palmas_clks_of_match_data structures are never modified.
> This patch constify them.
> 
> Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> ---

Applied to clk-next

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

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

* Re: [PATCH 2/2] clk: palmas: fix a possible NULL dereference
  2015-11-25 12:52 ` [PATCH 2/2] clk: palmas: fix a possible NULL dereference LABBE Corentin
@ 2016-01-30  0:58   ` Stephen Boyd
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2016-01-30  0:58 UTC (permalink / raw)
  To: LABBE Corentin; +Cc: mturquette, linux-clk, linux-kernel

On 11/25, LABBE Corentin wrote:
> of_match_device could return NULL, and so cause a NULL pointer
> dereference later.
> Even if the probability of this case is very low, fixing it made
> static analyzers happy.
> 
> Solving this with of_device_get_match_data made also code simplier.
> 
> Reported-by: coverity (CID 1324137)
> Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> ---

Applied to clk-next

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

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

end of thread, other threads:[~2016-01-30  0:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-25 12:52 [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure LABBE Corentin
2015-11-25 12:52 ` [PATCH 2/2] clk: palmas: fix a possible NULL dereference LABBE Corentin
2016-01-30  0:58   ` Stephen Boyd
2016-01-30  0:57 ` [PATCH 1/2] clk: palmas: constify the palmas_clks_of_match_data structure Stephen Boyd

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