@@ -100,6 +100,12 @@ static const struct mlxsw_cooling_states default_cooling_states[] = {
100100
101101struct mlxsw_thermal ;
102102
103+ struct mlxsw_thermal_cooling_device {
104+ struct mlxsw_thermal * thermal ;
105+ struct thermal_cooling_device * cdev ;
106+ unsigned int idx ;
107+ };
108+
103109struct mlxsw_thermal_module {
104110 struct mlxsw_thermal * parent ;
105111 struct thermal_zone_device * tzdev ;
@@ -123,7 +129,7 @@ struct mlxsw_thermal {
123129 const struct mlxsw_bus_info * bus_info ;
124130 struct thermal_zone_device * tzdev ;
125131 int polling_delay ;
126- struct thermal_cooling_device * cdevs [MLXSW_MFCR_PWMS_MAX ];
132+ struct mlxsw_thermal_cooling_device cdevs [MLXSW_MFCR_PWMS_MAX ];
127133 struct thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
128134 struct mlxsw_cooling_states cooling_states [MLXSW_THERMAL_NUM_TRIPS ];
129135 struct mlxsw_thermal_area line_cards [];
@@ -147,7 +153,7 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal,
147153 int i ;
148154
149155 for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ )
150- if (thermal -> cdevs [i ] == cdev )
156+ if (thermal -> cdevs [i ]. cdev == cdev )
151157 return i ;
152158
153159 /* Allow mlxsw thermal zone binding to an external cooling device */
@@ -352,17 +358,14 @@ static int mlxsw_thermal_get_cur_state(struct thermal_cooling_device *cdev,
352358 unsigned long * p_state )
353359
354360{
355- struct mlxsw_thermal * thermal = cdev -> devdata ;
361+ struct mlxsw_thermal_cooling_device * mlxsw_cdev = cdev -> devdata ;
362+ struct mlxsw_thermal * thermal = mlxsw_cdev -> thermal ;
356363 struct device * dev = thermal -> bus_info -> dev ;
357364 char mfsc_pl [MLXSW_REG_MFSC_LEN ];
358- int err , idx ;
359365 u8 duty ;
366+ int err ;
360367
361- idx = mlxsw_get_cooling_device_idx (thermal , cdev );
362- if (idx < 0 )
363- return idx ;
364-
365- mlxsw_reg_mfsc_pack (mfsc_pl , idx , 0 );
368+ mlxsw_reg_mfsc_pack (mfsc_pl , mlxsw_cdev -> idx , 0 );
366369 err = mlxsw_reg_query (thermal -> core , MLXSW_REG (mfsc ), mfsc_pl );
367370 if (err ) {
368371 dev_err (dev , "Failed to query PWM duty\n" );
@@ -378,22 +381,19 @@ static int mlxsw_thermal_set_cur_state(struct thermal_cooling_device *cdev,
378381 unsigned long state )
379382
380383{
381- struct mlxsw_thermal * thermal = cdev -> devdata ;
384+ struct mlxsw_thermal_cooling_device * mlxsw_cdev = cdev -> devdata ;
385+ struct mlxsw_thermal * thermal = mlxsw_cdev -> thermal ;
382386 struct device * dev = thermal -> bus_info -> dev ;
383387 char mfsc_pl [MLXSW_REG_MFSC_LEN ];
384- int idx ;
385388 int err ;
386389
387390 if (state > MLXSW_THERMAL_MAX_STATE )
388391 return - EINVAL ;
389392
390- idx = mlxsw_get_cooling_device_idx (thermal , cdev );
391- if (idx < 0 )
392- return idx ;
393-
394393 /* Normalize the state to the valid speed range. */
395394 state = max_t (unsigned long , MLXSW_THERMAL_MIN_STATE , state );
396- mlxsw_reg_mfsc_pack (mfsc_pl , idx , mlxsw_state_to_duty (state ));
395+ mlxsw_reg_mfsc_pack (mfsc_pl , mlxsw_cdev -> idx ,
396+ mlxsw_state_to_duty (state ));
397397 err = mlxsw_reg_write (thermal -> core , MLXSW_REG (mfsc ), mfsc_pl );
398398 if (err ) {
399399 dev_err (dev , "Failed to write PWM duty\n" );
@@ -753,17 +753,21 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
753753 }
754754 for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ ) {
755755 if (pwm_active & BIT (i )) {
756+ struct mlxsw_thermal_cooling_device * mlxsw_cdev ;
756757 struct thermal_cooling_device * cdev ;
757758
759+ mlxsw_cdev = & thermal -> cdevs [i ];
760+ mlxsw_cdev -> thermal = thermal ;
761+ mlxsw_cdev -> idx = i ;
758762 cdev = thermal_cooling_device_register ("mlxsw_fan" ,
759- thermal ,
763+ mlxsw_cdev ,
760764 & mlxsw_cooling_ops );
761765 if (IS_ERR (cdev )) {
762766 err = PTR_ERR (cdev );
763767 dev_err (dev , "Failed to register cooling device\n" );
764768 goto err_thermal_cooling_device_register ;
765769 }
766- thermal -> cdevs [ i ] = cdev ;
770+ mlxsw_cdev -> cdev = cdev ;
767771 }
768772 }
769773
@@ -824,8 +828,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
824828err_thermal_zone_device_register :
825829err_thermal_cooling_device_register :
826830 for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ )
827- if (thermal -> cdevs [i ])
828- thermal_cooling_device_unregister (thermal -> cdevs [i ]);
831+ thermal_cooling_device_unregister (thermal -> cdevs [i ].cdev );
829832err_reg_write :
830833err_reg_query :
831834 kfree (thermal );
@@ -847,12 +850,8 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
847850 thermal -> tzdev = NULL ;
848851 }
849852
850- for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ ) {
851- if (thermal -> cdevs [i ]) {
852- thermal_cooling_device_unregister (thermal -> cdevs [i ]);
853- thermal -> cdevs [i ] = NULL ;
854- }
855- }
853+ for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ )
854+ thermal_cooling_device_unregister (thermal -> cdevs [i ].cdev );
856855
857856 kfree (thermal );
858857}
0 commit comments