Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1696947 > unrolled thread
| Started by | <honghui.zhang@mediatek.com> |
|---|---|
| First post | 2017-07-26 12:00 +0200 |
| Last post | 2017-07-26 14:40 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] memory: mtk-smi: Use of_device_get_match_data helper <honghui.zhang@mediatek.com> - 2017-07-26 12:00 +0200
Re: [PATCH] memory: mtk-smi: Use of_device_get_match_data helper Robin Murphy <robin.murphy@arm.com> - 2017-07-26 12:40 +0200
Re: [PATCH] memory: mtk-smi: Use of_device_get_match_data helper Honghui Zhang <honghui.zhang@mediatek.com> - 2017-07-26 14:40 +0200
| From | <honghui.zhang@mediatek.com> |
|---|---|
| Date | 2017-07-26 12:00 +0200 |
| Subject | [PATCH] memory: mtk-smi: Use of_device_get_match_data helper |
| Message-ID | <u7rgL-77f-35@gated-at.bofh.it> |
From: Honghui Zhang <honghui.zhang@mediatek.com>
Replace custom code with generic helper to retrieve driver data.
Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
---
drivers/memory/mtk-smi.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index 4afbc41..fe8b81a 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -240,20 +240,15 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct device_node *smi_node;
struct platform_device *smi_pdev;
- const struct of_device_id *of_id;
if (!dev->pm_domain)
return -EPROBE_DEFER;
- of_id = of_match_node(mtk_smi_larb_of_ids, pdev->dev.of_node);
- if (!of_id)
- return -EINVAL;
-
larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
if (!larb)
return -ENOMEM;
- larb->larb_gen = of_id->data;
+ larb->larb_gen = of_device_get_match_data(dev);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
larb->base = devm_ioremap_resource(dev, res);
if (IS_ERR(larb->base))
@@ -319,8 +314,7 @@ static int mtk_smi_common_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct mtk_smi *common;
struct resource *res;
- const struct of_device_id *of_id;
- enum mtk_smi_gen smi_gen;
+ const enum mtk_smi_gen *smi_gen;
if (!dev->pm_domain)
return -EPROBE_DEFER;
@@ -338,18 +332,14 @@ static int mtk_smi_common_probe(struct platform_device *pdev)
if (IS_ERR(common->clk_smi))
return PTR_ERR(common->clk_smi);
- of_id = of_match_node(mtk_smi_common_of_ids, pdev->dev.of_node);
- if (!of_id)
- return -EINVAL;
-
/*
* for mtk smi gen 1, we need to get the ao(always on) base to config
* m4u port, and we need to enable the aync clock for transform the smi
* clock into emi clock domain, but for mtk smi gen2, there's no smi ao
* base.
*/
- smi_gen = (enum mtk_smi_gen)of_id->data;
- if (smi_gen == MTK_SMI_GEN1) {
+ smi_gen = of_device_get_match_data(dev);
+ if (*smi_gen == MTK_SMI_GEN1) {
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
common->smi_ao_base = devm_ioremap_resource(dev, res);
if (IS_ERR(common->smi_ao_base))
--
2.6.4
[toc] | [next] | [standalone]
| From | Robin Murphy <robin.murphy@arm.com> |
|---|---|
| Date | 2017-07-26 12:40 +0200 |
| Message-ID | <u7rTr-7zc-1@gated-at.bofh.it> |
| In reply to | #1696947 |
On 26/07/17 10:59, honghui.zhang@mediatek.com wrote:
> From: Honghui Zhang <honghui.zhang@mediatek.com>
>
> Replace custom code with generic helper to retrieve driver data.
>
> Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
> ---
> drivers/memory/mtk-smi.c | 18 ++++--------------
> 1 file changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
> index 4afbc41..fe8b81a 100644
> --- a/drivers/memory/mtk-smi.c
> +++ b/drivers/memory/mtk-smi.c
> @@ -240,20 +240,15 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct device_node *smi_node;
> struct platform_device *smi_pdev;
> - const struct of_device_id *of_id;
>
> if (!dev->pm_domain)
> return -EPROBE_DEFER;
>
> - of_id = of_match_node(mtk_smi_larb_of_ids, pdev->dev.of_node);
> - if (!of_id)
> - return -EINVAL;
> -
> larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
> if (!larb)
> return -ENOMEM;
>
> - larb->larb_gen = of_id->data;
> + larb->larb_gen = of_device_get_match_data(dev);
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> larb->base = devm_ioremap_resource(dev, res);
> if (IS_ERR(larb->base))
> @@ -319,8 +314,7 @@ static int mtk_smi_common_probe(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct mtk_smi *common;
> struct resource *res;
> - const struct of_device_id *of_id;
> - enum mtk_smi_gen smi_gen;
> + const enum mtk_smi_gen *smi_gen;
>
> if (!dev->pm_domain)
> return -EPROBE_DEFER;
> @@ -338,18 +332,14 @@ static int mtk_smi_common_probe(struct platform_device *pdev)
> if (IS_ERR(common->clk_smi))
> return PTR_ERR(common->clk_smi);
>
> - of_id = of_match_node(mtk_smi_common_of_ids, pdev->dev.of_node);
> - if (!of_id)
> - return -EINVAL;
> -
> /*
> * for mtk smi gen 1, we need to get the ao(always on) base to config
> * m4u port, and we need to enable the aync clock for transform the smi
> * clock into emi clock domain, but for mtk smi gen2, there's no smi ao
> * base.
> */
> - smi_gen = (enum mtk_smi_gen)of_id->data;
> - if (smi_gen == MTK_SMI_GEN1) {
> + smi_gen = of_device_get_match_data(dev);
The data you're retrieving is the exact same thing as of_id->data was,
i.e. an enum mtk_smi_gen cast to void*, so dereferencing it is not a
good idea. The first patch was almost right; you just need to keep the
cast in the assignment to smi_gen.
Robin.
> + if (*smi_gen == MTK_SMI_GEN1) {
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> common->smi_ao_base = devm_ioremap_resource(dev, res);
> if (IS_ERR(common->smi_ao_base))
>
[toc] | [prev] | [next] | [standalone]
| From | Honghui Zhang <honghui.zhang@mediatek.com> |
|---|---|
| Date | 2017-07-26 14:40 +0200 |
| Message-ID | <u7tLA-jq-19@gated-at.bofh.it> |
| In reply to | #1696967 |
On Wed, 2017-07-26 at 11:36 +0100, Robin Murphy wrote:
> On 26/07/17 10:59, honghui.zhang@mediatek.com wrote:
> > From: Honghui Zhang <honghui.zhang@mediatek.com>
> >
> > * for mtk smi gen 1, we need to get the ao(always on) base to config
> > * m4u port, and we need to enable the aync clock for transform the smi
> > * clock into emi clock domain, but for mtk smi gen2, there's no smi ao
> > * base.
> > */
> > - smi_gen = (enum mtk_smi_gen)of_id->data;
> > - if (smi_gen == MTK_SMI_GEN1) {
> > + smi_gen = of_device_get_match_data(dev);
>
> The data you're retrieving is the exact same thing as of_id->data was,
> i.e. an enum mtk_smi_gen cast to void*, so dereferencing it is not a
> good idea. The first patch was almost right; you just need to keep the
> cast in the assignment to smi_gen.
>
> Robin.
>
Hi, Robin, thanks very much.
I will send a new version.
> > + if (*smi_gen == MTK_SMI_GEN1) {
> > res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > common->smi_ao_base = devm_ioremap_resource(dev, res);
> > if (IS_ERR(common->smi_ao_base))
> >
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web