[PATCH] cpufreq: qcom-hw: Add missing null pointer check

Manivannan Sadhasivam posted 1 patch 2 years, 6 months ago
drivers/cpufreq/qcom-cpufreq-hw.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] cpufreq: qcom-hw: Add missing null pointer check
Posted by Manivannan Sadhasivam 2 years, 6 months ago
of_device_get_match_data() may return NULL, so add a check to prevent
potential null pointer dereference.

Issue reported by Qualcomm's internal static analysis tool.

Cc: stable@vger.kernel.org # v6.2
Fixes: 4f7961706c63 ("cpufreq: qcom-hw: Move soc_data to struct qcom_cpufreq")
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/cpufreq/qcom-cpufreq-hw.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
index 340fed35e45d..6425c6b6e393 100644
--- a/drivers/cpufreq/qcom-cpufreq-hw.c
+++ b/drivers/cpufreq/qcom-cpufreq-hw.c
@@ -689,6 +689,8 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	qcom_cpufreq.soc_data = of_device_get_match_data(dev);
+	if (!qcom_cpufreq.soc_data)
+		return -ENODEV;
 
 	clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, num_domains), GFP_KERNEL);
 	if (!clk_data)
-- 
2.25.1
Re: [PATCH] cpufreq: qcom-hw: Add missing null pointer check
Posted by Viresh Kumar 2 years, 6 months ago
On 14-02-23, 15:11, Manivannan Sadhasivam wrote:
> of_device_get_match_data() may return NULL, so add a check to prevent
> potential null pointer dereference.
> 
> Issue reported by Qualcomm's internal static analysis tool.
> 
> Cc: stable@vger.kernel.org # v6.2
> Fixes: 4f7961706c63 ("cpufreq: qcom-hw: Move soc_data to struct qcom_cpufreq")
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/cpufreq/qcom-cpufreq-hw.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
> index 340fed35e45d..6425c6b6e393 100644
> --- a/drivers/cpufreq/qcom-cpufreq-hw.c
> +++ b/drivers/cpufreq/qcom-cpufreq-hw.c
> @@ -689,6 +689,8 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	qcom_cpufreq.soc_data = of_device_get_match_data(dev);
> +	if (!qcom_cpufreq.soc_data)
> +		return -ENODEV;
>  
>  	clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, num_domains), GFP_KERNEL);
>  	if (!clk_data)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Rafael,

Can you still send this for 6.2 ?

-- 
viresh
Re: [PATCH] cpufreq: qcom-hw: Add missing null pointer check
Posted by Rafael J. Wysocki 2 years, 6 months ago
On Tue, Feb 14, 2023 at 10:53 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 14-02-23, 15:11, Manivannan Sadhasivam wrote:
> > of_device_get_match_data() may return NULL, so add a check to prevent
> > potential null pointer dereference.
> >
> > Issue reported by Qualcomm's internal static analysis tool.
> >
> > Cc: stable@vger.kernel.org # v6.2
> > Fixes: 4f7961706c63 ("cpufreq: qcom-hw: Move soc_data to struct qcom_cpufreq")
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >  drivers/cpufreq/qcom-cpufreq-hw.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
> > index 340fed35e45d..6425c6b6e393 100644
> > --- a/drivers/cpufreq/qcom-cpufreq-hw.c
> > +++ b/drivers/cpufreq/qcom-cpufreq-hw.c
> > @@ -689,6 +689,8 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
> >               return -ENOMEM;
> >
> >       qcom_cpufreq.soc_data = of_device_get_match_data(dev);
> > +     if (!qcom_cpufreq.soc_data)
> > +             return -ENODEV;
> >
> >       clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, num_domains), GFP_KERNEL);
> >       if (!clk_data)
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
>
> Rafael,
>
> Can you still send this for 6.2 ?

Yes, I can.