tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master head: 82e4255305c554b0bb18b7ccf2db86041b4c8b6e commit: c6ed48ef52599098498a8442fd60bea5bd8cd309 [9580/10049] power: supply: add ChromeOS EC based charge control driver config: x86_64-randconfig-161-20240703 (https://download.01.org/0day-ci/archive/20240703/202407030856.WDIxlKzW-lkp@xxxxxxxxx/config) compiler: gcc-9 (Ubuntu 9.5.0-4ubuntu2) 9.5.0 If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@xxxxxxxxx> | Closes: https://lore.kernel.org/oe-kbuild-all/202407030856.WDIxlKzW-lkp@xxxxxxxxx/ smatch warnings: drivers/power/supply/cros_charge-control.c:210 charge_behaviour_store() warn: unsigned 'behaviour' is never less than zero. drivers/power/supply/cros_charge-control.c:297 cros_chctl_probe() error: buffer overflow 'priv->attributes' 3 <= 3 vim +/behaviour +210 drivers/power/supply/cros_charge-control.c 200 201 static ssize_t charge_behaviour_store(struct device *dev, struct device_attribute *attr, 202 const char *buf, size_t count) 203 { 204 struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr, 205 CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR); 206 enum power_supply_charge_behaviour behaviour; 207 int ret; 208 209 behaviour = power_supply_charge_behaviour_parse(EC_CHARGE_CONTROL_BEHAVIOURS, buf); > 210 if (behaviour < 0) 211 return behaviour; 212 213 priv->current_behaviour = behaviour; 214 215 ret = cros_chctl_configure_ec(priv); 216 if (ret < 0) 217 return ret; 218 219 return count; 220 } 221 222 static umode_t cros_chtl_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 223 { 224 struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(attr, n); 225 226 if (priv->cmd_version < 2) { 227 if (n == CROS_CHCTL_ATTR_START_THRESHOLD) 228 return 0; 229 if (n == CROS_CHCTL_ATTR_END_THRESHOLD) 230 return 0; 231 } 232 233 return attr->mode; 234 } 235 236 static int cros_chctl_add_battery(struct power_supply *battery, struct acpi_battery_hook *hook) 237 { 238 struct cros_chctl_priv *priv = container_of(hook, struct cros_chctl_priv, battery_hook); 239 240 if (priv->hooked_battery) 241 return 0; 242 243 priv->hooked_battery = battery; 244 return device_add_group(&battery->dev, &priv->group); 245 } 246 247 static int cros_chctl_remove_battery(struct power_supply *battery, struct acpi_battery_hook *hook) 248 { 249 struct cros_chctl_priv *priv = container_of(hook, struct cros_chctl_priv, battery_hook); 250 251 if (priv->hooked_battery == battery) { 252 device_remove_group(&battery->dev, &priv->group); 253 priv->hooked_battery = NULL; 254 } 255 256 return 0; 257 } 258 259 static int cros_chctl_probe(struct platform_device *pdev) 260 { 261 struct device *dev = &pdev->dev; 262 struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent); 263 struct cros_ec_device *cros_ec = ec_dev->ec_dev; 264 struct cros_chctl_priv *priv; 265 size_t i; 266 int ret; 267 268 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 269 if (!priv) 270 return -ENOMEM; 271 272 ret = cros_ec_get_cmd_versions(cros_ec, EC_CMD_CHARGE_CONTROL); 273 if (ret < 0) 274 return ret; 275 else if (ret & EC_VER_MASK(3)) 276 priv->cmd_version = 3; 277 else if (ret & EC_VER_MASK(2)) 278 priv->cmd_version = 2; 279 else if (ret & EC_VER_MASK(1)) 280 priv->cmd_version = 1; 281 else 282 return -ENODEV; 283 284 dev_dbg(dev, "Command version: %u\n", (unsigned int)priv->cmd_version); 285 286 priv->cros_ec = cros_ec; 287 priv->device_attrs[CROS_CHCTL_ATTR_START_THRESHOLD] = 288 (struct device_attribute)__ATTR_RW(charge_control_start_threshold); 289 priv->device_attrs[CROS_CHCTL_ATTR_END_THRESHOLD] = 290 (struct device_attribute)__ATTR_RW(charge_control_end_threshold); 291 priv->device_attrs[CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR] = 292 (struct device_attribute)__ATTR_RW(charge_behaviour); 293 for (i = 0; i < _CROS_CHCTL_ATTR_COUNT; i++) { 294 sysfs_attr_init(&priv->device_attrs[i].attr); 295 priv->attributes[i] = &priv->device_attrs[i].attr; 296 } > 297 priv->attributes[_CROS_CHCTL_ATTR_COUNT] = NULL; 298 priv->group.is_visible = cros_chtl_attr_is_visible; 299 priv->group.attrs = priv->attributes; 300 301 priv->battery_hook.name = dev_name(dev); 302 priv->battery_hook.add_battery = cros_chctl_add_battery; 303 priv->battery_hook.remove_battery = cros_chctl_remove_battery; 304 305 priv->current_behaviour = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO; 306 priv->current_start_threshold = 0; 307 priv->current_end_threshold = 100; 308 309 /* Bring EC into well-known state */ 310 ret = cros_chctl_configure_ec(priv); 311 if (ret < 0) 312 return ret; 313 314 return devm_battery_hook_register(dev, &priv->battery_hook); 315 } 316 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki