Re: [PATCH V1 12/15] spmi-pmic-arb: fix a possible null pointer dereference
On 2017-05-31 22:59, Stephen Boyd wrote: On 05/30, Kiran Gunda wrote: diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 2afe359..412481d 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -1003,6 +1003,12 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pa->spmic = ctrl; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (!res) { + dev_err(>dev, "core resource not specified\n"); + err = -EINVAL; + goto err_put_ctrl; + } + pa->core_size = resource_size(res); if (pa->core_size <= 0x800) { dev_err(>dev, "core_size is smaller than 0x800. Failing Probe\n"); I would prefer this patch instead, so that we can piggyback on the error checking of the devm_ioremap_resource() code. Also, add a Fixes: tag please so we can backport it as needed. Sure. We will modify as per your suggestion in the next patch. diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 5ec3a595dc7d..0cedbda60707 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -878,12 +878,12 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pa->spmic = ctrl; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); - pa->core_size = resource_size(res); core = devm_ioremap_resource(>dev, res); if (IS_ERR(core)) { err = PTR_ERR(core); goto err_put_ctrl; } + pa->core_size = resource_size(res); hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); is_v1 = (hw_ver < PMIC_ARB_VERSION_V2_MIN);
Re: [PATCH V1 12/15] spmi-pmic-arb: fix a possible null pointer dereference
On 2017-05-31 22:59, Stephen Boyd wrote: On 05/30, Kiran Gunda wrote: diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 2afe359..412481d 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -1003,6 +1003,12 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pa->spmic = ctrl; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (!res) { + dev_err(>dev, "core resource not specified\n"); + err = -EINVAL; + goto err_put_ctrl; + } + pa->core_size = resource_size(res); if (pa->core_size <= 0x800) { dev_err(>dev, "core_size is smaller than 0x800. Failing Probe\n"); I would prefer this patch instead, so that we can piggyback on the error checking of the devm_ioremap_resource() code. Also, add a Fixes: tag please so we can backport it as needed. Sure. We will modify as per your suggestion in the next patch. diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 5ec3a595dc7d..0cedbda60707 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -878,12 +878,12 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pa->spmic = ctrl; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); - pa->core_size = resource_size(res); core = devm_ioremap_resource(>dev, res); if (IS_ERR(core)) { err = PTR_ERR(core); goto err_put_ctrl; } + pa->core_size = resource_size(res); hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); is_v1 = (hw_ver < PMIC_ARB_VERSION_V2_MIN);
Re: [PATCH V1 12/15] spmi-pmic-arb: fix a possible null pointer dereference
On 05/30, Kiran Gunda wrote: > diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c > index 2afe359..412481d 100644 > --- a/drivers/spmi/spmi-pmic-arb.c > +++ b/drivers/spmi/spmi-pmic-arb.c > @@ -1003,6 +1003,12 @@ static int spmi_pmic_arb_probe(struct platform_device > *pdev) > pa->spmic = ctrl; > > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); > + if (!res) { > + dev_err(>dev, "core resource not specified\n"); > + err = -EINVAL; > + goto err_put_ctrl; > + } > + > pa->core_size = resource_size(res); > if (pa->core_size <= 0x800) { > dev_err(>dev, "core_size is smaller than 0x800. Failing > Probe\n"); I would prefer this patch instead, so that we can piggyback on the error checking of the devm_ioremap_resource() code. Also, add a Fixes: tag please so we can backport it as needed. diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 5ec3a595dc7d..0cedbda60707 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -878,12 +878,12 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pa->spmic = ctrl; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); - pa->core_size = resource_size(res); core = devm_ioremap_resource(>dev, res); if (IS_ERR(core)) { err = PTR_ERR(core); goto err_put_ctrl; } + pa->core_size = resource_size(res); hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); is_v1 = (hw_ver < PMIC_ARB_VERSION_V2_MIN); -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH V1 12/15] spmi-pmic-arb: fix a possible null pointer dereference
On 05/30, Kiran Gunda wrote: > diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c > index 2afe359..412481d 100644 > --- a/drivers/spmi/spmi-pmic-arb.c > +++ b/drivers/spmi/spmi-pmic-arb.c > @@ -1003,6 +1003,12 @@ static int spmi_pmic_arb_probe(struct platform_device > *pdev) > pa->spmic = ctrl; > > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); > + if (!res) { > + dev_err(>dev, "core resource not specified\n"); > + err = -EINVAL; > + goto err_put_ctrl; > + } > + > pa->core_size = resource_size(res); > if (pa->core_size <= 0x800) { > dev_err(>dev, "core_size is smaller than 0x800. Failing > Probe\n"); I would prefer this patch instead, so that we can piggyback on the error checking of the devm_ioremap_resource() code. Also, add a Fixes: tag please so we can backport it as needed. diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 5ec3a595dc7d..0cedbda60707 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -878,12 +878,12 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pa->spmic = ctrl; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); - pa->core_size = resource_size(res); core = devm_ioremap_resource(>dev, res); if (IS_ERR(core)) { err = PTR_ERR(core); goto err_put_ctrl; } + pa->core_size = resource_size(res); hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); is_v1 = (hw_ver < PMIC_ARB_VERSION_V2_MIN); -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project