@@ -32,7 +32,6 @@ enum tpm_const {
3232 TPM_MINOR = 224 , /* officially assigned */
3333 TPM_BUFSIZE = 2048 ,
3434 TPM_NUM_DEVICES = 256 ,
35- TPM_NUM_MASK_ENTRIES = TPM_NUM_DEVICES / (8 * sizeof (int ))
3635};
3736
3837enum tpm_duration {
@@ -48,7 +47,7 @@ enum tpm_duration {
4847
4948static LIST_HEAD (tpm_chip_list );
5049static DEFINE_SPINLOCK (driver_lock );
51- static int dev_mask [ TPM_NUM_MASK_ENTRIES ] ;
50+ static DECLARE_BITMAP ( dev_mask , TPM_NUM_DEVICES ) ;
5251
5352/*
5453 * Array with one entry per ordinal defining the maximum amount
@@ -1038,8 +1037,7 @@ void tpm_remove_hardware(struct device *dev)
10381037 sysfs_remove_group (& dev -> kobj , chip -> vendor .attr_group );
10391038 tpm_bios_log_teardown (chip -> bios_dir );
10401039
1041- dev_mask [chip -> dev_num / TPM_NUM_MASK_ENTRIES ] &=
1042- ~(1 << (chip -> dev_num % TPM_NUM_MASK_ENTRIES ));
1040+ clear_bit (chip -> dev_num , dev_mask );
10431041
10441042 kfree (chip );
10451043
@@ -1097,7 +1095,6 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
10971095
10981096 char * devname ;
10991097 struct tpm_chip * chip ;
1100- int i , j ;
11011098
11021099 /* Driver specific per-device data */
11031100 chip = kzalloc (sizeof (* chip ), GFP_KERNEL );
@@ -1116,19 +1113,9 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
11161113
11171114 memcpy (& chip -> vendor , entry , sizeof (struct tpm_vendor_specific ));
11181115
1119- chip -> dev_num = -1 ;
1116+ chip -> dev_num = find_first_zero_bit ( dev_mask , TPM_NUM_DEVICES ) ;
11201117
1121- for (i = 0 ; i < TPM_NUM_MASK_ENTRIES ; i ++ )
1122- for (j = 0 ; j < 8 * sizeof (int ); j ++ )
1123- if ((dev_mask [i ] & (1 << j )) == 0 ) {
1124- chip -> dev_num =
1125- i * TPM_NUM_MASK_ENTRIES + j ;
1126- dev_mask [i ] |= 1 << j ;
1127- goto dev_num_search_complete ;
1128- }
1129-
1130- dev_num_search_complete :
1131- if (chip -> dev_num < 0 ) {
1118+ if (chip -> dev_num >= TPM_NUM_DEVICES ) {
11321119 dev_err (dev , "No available tpm device numbers\n" );
11331120 kfree (chip );
11341121 return NULL ;
@@ -1137,6 +1124,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
11371124 else
11381125 chip -> vendor .miscdev .minor = MISC_DYNAMIC_MINOR ;
11391126
1127+ set_bit (chip -> dev_num , dev_mask );
1128+
11401129 devname = kmalloc (DEVNAME_SIZE , GFP_KERNEL );
11411130 scnprintf (devname , DEVNAME_SIZE , "%s%d" , "tpm" , chip -> dev_num );
11421131 chip -> vendor .miscdev .name = devname ;
@@ -1150,8 +1139,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
11501139 chip -> vendor .miscdev .name ,
11511140 chip -> vendor .miscdev .minor );
11521141 put_device (dev );
1142+ clear_bit (chip -> dev_num , dev_mask );
11531143 kfree (chip );
1154- dev_mask [i ] &= !(1 << j );
11551144 return NULL ;
11561145 }
11571146
0 commit comments