@@ -566,6 +566,8 @@ static int applesmc_init_smcreg_try(void)
566566 if (ret )
567567 return ret ;
568568 s -> fan_count = tmp [0 ];
569+ if (s -> fan_count > 10 )
570+ s -> fan_count = 10 ;
569571
570572 ret = applesmc_get_lower_bound (& s -> temp_begin , "T" );
571573 if (ret )
@@ -811,7 +813,8 @@ static ssize_t applesmc_show_fan_speed(struct device *dev,
811813 char newkey [5 ];
812814 u8 buffer [2 ];
813815
814- sprintf (newkey , fan_speed_fmt [to_option (attr )], to_index (attr ));
816+ scnprintf (newkey , sizeof (newkey ), fan_speed_fmt [to_option (attr )],
817+ to_index (attr ));
815818
816819 ret = applesmc_read_key (newkey , buffer , 2 );
817820 speed = ((buffer [0 ] << 8 | buffer [1 ]) >> 2 );
@@ -834,7 +837,8 @@ static ssize_t applesmc_store_fan_speed(struct device *dev,
834837 if (kstrtoul (sysfsbuf , 10 , & speed ) < 0 || speed >= 0x4000 )
835838 return - EINVAL ; /* Bigger than a 14-bit value */
836839
837- sprintf (newkey , fan_speed_fmt [to_option (attr )], to_index (attr ));
840+ scnprintf (newkey , sizeof (newkey ), fan_speed_fmt [to_option (attr )],
841+ to_index (attr ));
838842
839843 buffer [0 ] = (speed >> 6 ) & 0xff ;
840844 buffer [1 ] = (speed << 2 ) & 0xff ;
@@ -903,7 +907,7 @@ static ssize_t applesmc_show_fan_position(struct device *dev,
903907 char newkey [5 ];
904908 u8 buffer [17 ];
905909
906- sprintf (newkey , FAN_ID_FMT , to_index (attr ));
910+ scnprintf (newkey , sizeof ( newkey ) , FAN_ID_FMT , to_index (attr ));
907911
908912 ret = applesmc_read_key (newkey , buffer , 16 );
909913 buffer [16 ] = 0 ;
@@ -1116,7 +1120,8 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
11161120 }
11171121 for (i = 0 ; i < num ; i ++ ) {
11181122 node = & grp -> nodes [i ];
1119- sprintf (node -> name , grp -> format , i + 1 );
1123+ scnprintf (node -> name , sizeof (node -> name ), grp -> format ,
1124+ i + 1 );
11201125 node -> sda .index = (grp -> option << 16 ) | (i & 0xffff );
11211126 node -> sda .dev_attr .show = grp -> show ;
11221127 node -> sda .dev_attr .store = grp -> store ;
0 commit comments