@@ -544,14 +544,15 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
544544 if (state > cdev -> max_state )
545545 return - EINVAL ;
546546
547- mutex_lock ( & cdev -> lock );
547+ guard ( cooling_dev )( cdev );
548548
549549 result = cdev -> ops -> set_cur_state (cdev , state );
550- if (!result )
551- thermal_cooling_device_stats_update (cdev , state );
550+ if (result )
551+ return result ;
552+
553+ thermal_cooling_device_stats_update (cdev , state );
552554
553- mutex_unlock (& cdev -> lock );
554- return result ? result : count ;
555+ return count ;
555556}
556557
557558static struct device_attribute
@@ -625,21 +626,18 @@ static ssize_t total_trans_show(struct device *dev,
625626{
626627 struct thermal_cooling_device * cdev = to_cooling_device (dev );
627628 struct cooling_dev_stats * stats ;
628- int ret = 0 ;
629+ int ret ;
629630
630- mutex_lock ( & cdev -> lock );
631+ guard ( cooling_dev )( cdev );
631632
632633 stats = cdev -> stats ;
633634 if (!stats )
634- goto unlock ;
635+ return 0 ;
635636
636637 spin_lock (& stats -> lock );
637638 ret = sprintf (buf , "%u\n" , stats -> total_trans );
638639 spin_unlock (& stats -> lock );
639640
640- unlock :
641- mutex_unlock (& cdev -> lock );
642-
643641 return ret ;
644642}
645643
@@ -652,11 +650,11 @@ time_in_state_ms_show(struct device *dev, struct device_attribute *attr,
652650 ssize_t len = 0 ;
653651 int i ;
654652
655- mutex_lock ( & cdev -> lock );
653+ guard ( cooling_dev )( cdev );
656654
657655 stats = cdev -> stats ;
658656 if (!stats )
659- goto unlock ;
657+ return 0 ;
660658
661659 spin_lock (& stats -> lock );
662660
@@ -668,9 +666,6 @@ time_in_state_ms_show(struct device *dev, struct device_attribute *attr,
668666 }
669667 spin_unlock (& stats -> lock );
670668
671- unlock :
672- mutex_unlock (& cdev -> lock );
673-
674669 return len ;
675670}
676671
@@ -682,11 +677,11 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf,
682677 struct cooling_dev_stats * stats ;
683678 int i , states ;
684679
685- mutex_lock ( & cdev -> lock );
680+ guard ( cooling_dev )( cdev );
686681
687682 stats = cdev -> stats ;
688683 if (!stats )
689- goto unlock ;
684+ return count ;
690685
691686 states = cdev -> max_state + 1 ;
692687
@@ -702,9 +697,6 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf,
702697
703698 spin_unlock (& stats -> lock );
704699
705- unlock :
706- mutex_unlock (& cdev -> lock );
707-
708700 return count ;
709701}
710702
@@ -716,13 +708,11 @@ static ssize_t trans_table_show(struct device *dev,
716708 ssize_t len = 0 ;
717709 int i , j ;
718710
719- mutex_lock ( & cdev -> lock );
711+ guard ( cooling_dev )( cdev );
720712
721713 stats = cdev -> stats ;
722- if (!stats ) {
723- len = - ENODATA ;
724- goto unlock ;
725- }
714+ if (!stats )
715+ return - ENODATA ;
726716
727717 len += snprintf (buf + len , PAGE_SIZE - len , " From : To\n" );
728718 len += snprintf (buf + len , PAGE_SIZE - len , " : " );
@@ -731,10 +721,8 @@ static ssize_t trans_table_show(struct device *dev,
731721 break ;
732722 len += snprintf (buf + len , PAGE_SIZE - len , "state%2u " , i );
733723 }
734- if (len >= PAGE_SIZE ) {
735- len = PAGE_SIZE ;
736- goto unlock ;
737- }
724+ if (len >= PAGE_SIZE )
725+ return PAGE_SIZE ;
738726
739727 len += snprintf (buf + len , PAGE_SIZE - len , "\n" );
740728
@@ -760,9 +748,6 @@ static ssize_t trans_table_show(struct device *dev,
760748 len = - EFBIG ;
761749 }
762750
763- unlock :
764- mutex_unlock (& cdev -> lock );
765-
766751 return len ;
767752}
768753
0 commit comments