Skip to contentSkip to conversation

charger-manager: Modify the way of checking battery's temperature

DISCUSSION Dan Carpenter 2 participants 2 messages Jan 7, 2014 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello Jonghwa Lee,

The patch 5c49a6256bed: "charger-manager: Modify the way of checking battery's temperature" from Dec 18, 2013, leads to the following static checker warning:

drivers/power/charger-manager.c:563 cm_get_battery_temperature()
warn: passing casted pointer 'temp' to 'thermal_zone_get_temp()' 32 vs 64.

drivers/power/charger-manager.c
554 static int cm_get_battery_temperature(struct charger_manager *cm,
555 int *temp)
556 {
557 int ret;
558
559 if (!cm->desc->measure_battery_temp)
560 return -ENODEV;
561
562 #ifdef CONFIG_THERMAL

   563          ret = thermal_zone_get_temp(cm->tzd_batt, (unsigned long *)temp);
                                                          ^^^^^^^^^^^^^^^^^^^^^^

This will corrupt memory on 64 bit systems.

564 if (!ret)
565 /* Calibrate temperature unit */
566 *temp /= 100;
567 #else
568 ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
569 POWER_SUPPLY_PROP_TEMP,

   570                                  (union power_supply_propval *)temp);
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This will corrupt memory as well. Some of the callers pass an actual 32 bit integer and not a 64 bit union.

571 #endif
572 return ret;
573 }

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi,

Quoted 31 lines · Dan Carpenter

Hello Jonghwa Lee,

The patch 5c49a6256bed: "charger-manager: Modify the way of checking battery's temperature" from Dec 18, 2013, leads to the following static checker warning:

drivers/power/charger-manager.c:563 cm_get_battery_temperature()
warn: passing casted pointer 'temp' to 'thermal_zone_get_temp()' 32 vs 64.

drivers/power/charger-manager.c
554 static int cm_get_battery_temperature(struct charger_manager *cm,
555 int *temp)

   556  {
   557          int ret;
   558  
   559          if (!cm->desc->measure_battery_temp)
   560                  return -ENODEV;
   561  
   562  #ifdef CONFIG_THERMAL
   563          ret = thermal_zone_get_temp(cm->tzd_batt, (unsigned long *)temp);
                                                          ^^^^^^^^^^^^^^^^^^^^^^

This will corrupt memory on 64 bit systems.

   564          if (!ret)
   565                  /* Calibrate temperature unit */
   566                  *temp /= 100;
   567  #else
   568          ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
   569                                  POWER_SUPPLY_PROP_TEMP,
   570                                  (union power_supply_propval *)temp);
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 7 lines

This will corrupt memory as well. Some of the callers pass an actual 32 bit integer and not a 64 bit union.

   571  #endif
   572          return ret;
   573  }

Sorry, I carelessly used typecasting. I'll clean these up. Thanks for advice.

Thanks,
Jonghwa

Quoted 4 lines

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html