hwmon: cros_ec_hwmon: Add NULL check in cros_ec_hwmon_probe_temp_sensors devm_kasprintf() can return a NULL pointer on failure, but "priv->temp_sensor_names[i]" returned value in cros_ec_hwmon_probe_temp_sensors is not checked. Add NULL check in cros_ec_hwmon_probe_temp_sensors, to handle kernel NULL pointer dereference error.
There's no actual NULL pointer dereference. If the memory allocation failed, cros_ec_hwmon_is_visible() will set the attributes permissions to 0, which means the attribute will not be created. This means cros_ec_hwmon_read_string(), the only function which makes use of this pointer, will never be called for this attribute. We could report the memory shortage, but I seem to recall the low-level memory allocation functions are already doing that so it would be redundant. We could also catch the error and fail the device probing altogether, but I can't see how this would improve the situation. So I believe the best course of action is to leave the code as is.
(In reply to Jean Delvare from comment #1) > There's no actual NULL pointer dereference. If the memory allocation failed, > cros_ec_hwmon_is_visible() will set the attributes permissions to 0, which > means the attribute will not be created. This means > cros_ec_hwmon_read_string(), the only function which makes use of this > pointer, will never be called for this attribute. > > We could report the memory shortage, but I seem to recall the low-level > memory allocation functions are already doing that so it would be redundant. > We could also catch the error and fail the device probing altogether, but I > can't see how this would improve the situation. > > So I believe the best course of action is to leave the code as is. Thank you for the detailed explanation. I'll drop this patch and mark it as "Not Needed" in my records. Appreciate your time reviewing this!