1212
1313struct nvme_hwmon_data {
1414 struct nvme_ctrl * ctrl ;
15- struct nvme_smart_log log ;
15+ struct nvme_smart_log * log ;
1616 struct mutex read_lock ;
1717};
1818
@@ -60,14 +60,14 @@ static int nvme_set_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under,
6060static int nvme_hwmon_get_smart_log (struct nvme_hwmon_data * data )
6161{
6262 return nvme_get_log (data -> ctrl , NVME_NSID_ALL , NVME_LOG_SMART , 0 ,
63- NVME_CSI_NVM , & data -> log , sizeof (data -> log ), 0 );
63+ NVME_CSI_NVM , data -> log , sizeof (* data -> log ), 0 );
6464}
6565
6666static int nvme_hwmon_read (struct device * dev , enum hwmon_sensor_types type ,
6767 u32 attr , int channel , long * val )
6868{
6969 struct nvme_hwmon_data * data = dev_get_drvdata (dev );
70- struct nvme_smart_log * log = & data -> log ;
70+ struct nvme_smart_log * log = data -> log ;
7171 int temp ;
7272 int err ;
7373
@@ -163,7 +163,7 @@ static umode_t nvme_hwmon_is_visible(const void *_data,
163163 case hwmon_temp_max :
164164 case hwmon_temp_min :
165165 if ((!channel && data -> ctrl -> wctemp ) ||
166- (channel && data -> log . temp_sensor [channel - 1 ])) {
166+ (channel && data -> log -> temp_sensor [channel - 1 ])) {
167167 if (data -> ctrl -> quirks &
168168 NVME_QUIRK_NO_TEMP_THRESH_CHANGE )
169169 return 0444 ;
@@ -176,7 +176,7 @@ static umode_t nvme_hwmon_is_visible(const void *_data,
176176 break ;
177177 case hwmon_temp_input :
178178 case hwmon_temp_label :
179- if (!channel || data -> log . temp_sensor [channel - 1 ])
179+ if (!channel || data -> log -> temp_sensor [channel - 1 ])
180180 return 0444 ;
181181 break ;
182182 default :
@@ -230,28 +230,39 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
230230
231231 data = kzalloc (sizeof (* data ), GFP_KERNEL );
232232 if (!data )
233- return 0 ;
233+ return - ENOMEM ;
234+
235+ data -> log = kzalloc (sizeof (* data -> log ), GFP_KERNEL );
236+ if (!data -> log ) {
237+ err = - ENOMEM ;
238+ goto err_free_data ;
239+ }
234240
235241 data -> ctrl = ctrl ;
236242 mutex_init (& data -> read_lock );
237243
238244 err = nvme_hwmon_get_smart_log (data );
239245 if (err ) {
240246 dev_warn (dev , "Failed to read smart log (error %d)\n" , err );
241- kfree (data );
242- return err ;
247+ goto err_free_log ;
243248 }
244249
245250 hwmon = hwmon_device_register_with_info (dev , "nvme" ,
246251 data , & nvme_hwmon_chip_info ,
247252 NULL );
248253 if (IS_ERR (hwmon )) {
249254 dev_warn (dev , "Failed to instantiate hwmon device\n" );
250- kfree ( data );
251- return PTR_ERR ( hwmon ) ;
255+ err = PTR_ERR ( hwmon );
256+ goto err_free_log ;
252257 }
253258 ctrl -> hwmon_device = hwmon ;
254259 return 0 ;
260+
261+ err_free_log :
262+ kfree (data -> log );
263+ err_free_data :
264+ kfree (data );
265+ return err ;
255266}
256267
257268void nvme_hwmon_exit (struct nvme_ctrl * ctrl )
@@ -262,6 +273,7 @@ void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
262273
263274 hwmon_device_unregister (ctrl -> hwmon_device );
264275 ctrl -> hwmon_device = NULL ;
276+ kfree (data -> log );
265277 kfree (data );
266278 }
267279}
0 commit comments