diff mbox

thermal: ti-soc-thermal: Potential error pointer dereferences

Message ID 20170710072422.rs25i5oawmiaofrp@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter July 10, 2017, 7:24 a.m. UTC
ti_bandgap_get_sensor_data() can return error pointers so we should
check for that.  There is no need to check "data->ti_thermal" for NULL
and we removed that from the other cleanup function so we may as well
from it in ti_thermal_remove_sensor() to be consistent.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Zhang Rui Aug. 11, 2017, 2 a.m. UTC | #1
On Mon, 2017-07-10 at 10:24 +0300, Dan Carpenter wrote:
> ti_bandgap_get_sensor_data() can return error pointers so we should
> check for that.  There is no need to check "data->ti_thermal" for
> NULL
> and we removed that from the other cleanup function so we may as well
> from it in ti_thermal_remove_sensor() to be consistent.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> index c211a8e4a210..9fea354ca90c 100644
> --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> @@ -210,7 +210,7 @@ int ti_thermal_remove_sensor(struct ti_bandgap
> *bgp, int id)
>  
>  	data = ti_bandgap_get_sensor_data(bgp, id);
>  
> -	if (data && data->ti_thermal) {
> +	if (data && !IS_ERR(data)) {

what about
	if (!IS_ERR_OR_NULL(data))

thanks,
rui

>  		if (data->our_zone)
>  			thermal_zone_device_unregister(data-
> >ti_thermal);
>  	}
> @@ -276,7 +276,7 @@ int ti_thermal_unregister_cpu_cooling(struct
> ti_bandgap *bgp, int id)
>  
>  	data = ti_bandgap_get_sensor_data(bgp, id);
>  
> -	if (data) {
> +	if (data && !IS_ERR(data)) {
>  		cpufreq_cooling_unregister(data->cool_dev);
>  		cpufreq_cpu_put(data->policy);
>  	}
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Carpenter Aug. 11, 2017, 7:55 a.m. UTC | #2
On Fri, Aug 11, 2017 at 10:00:33AM +0800, Zhang Rui wrote:
> On Mon, 2017-07-10 at 10:24 +0300, Dan Carpenter wrote:
> > ti_bandgap_get_sensor_data() can return error pointers so we should
> > check for that.  There is no need to check "data->ti_thermal" for
> > NULL
> > and we removed that from the other cleanup function so we may as well
> > from it in ti_thermal_remove_sensor() to be consistent.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> > b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> > index c211a8e4a210..9fea354ca90c 100644
> > --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> > +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> > @@ -210,7 +210,7 @@ int ti_thermal_remove_sensor(struct ti_bandgap
> > *bgp, int id)
> >  
> >  	data = ti_bandgap_get_sensor_data(bgp, id);
> >  
> > -	if (data && data->ti_thermal) {
> > +	if (data && !IS_ERR(data)) {
> 
> what about
> 	if (!IS_ERR_OR_NULL(data))
> 

Duh.  Of course, let me resend.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index c211a8e4a210..9fea354ca90c 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -210,7 +210,7 @@  int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id)
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (data && data->ti_thermal) {
+	if (data && !IS_ERR(data)) {
 		if (data->our_zone)
 			thermal_zone_device_unregister(data->ti_thermal);
 	}
@@ -276,7 +276,7 @@  int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (data) {
+	if (data && !IS_ERR(data)) {
 		cpufreq_cooling_unregister(data->cool_dev);
 		cpufreq_cpu_put(data->policy);
 	}