Commit 10685a95 authored by Kylene Jo Hall's avatar Kylene Jo Hall Committed by Linus Torvalds

[PATCH] tpm: use clear_bit

Use set_bit() and clear_bit() for dev_mask manipulation.
Signed-off-by: default avatarKylie Hall <kjhall@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 36b20020
...@@ -32,7 +32,6 @@ enum tpm_const { ...@@ -32,7 +32,6 @@ enum tpm_const {
TPM_MINOR = 224, /* officially assigned */ TPM_MINOR = 224, /* officially assigned */
TPM_BUFSIZE = 2048, TPM_BUFSIZE = 2048,
TPM_NUM_DEVICES = 256, TPM_NUM_DEVICES = 256,
TPM_NUM_MASK_ENTRIES = TPM_NUM_DEVICES / (8 * sizeof(int))
}; };
enum tpm_duration { enum tpm_duration {
...@@ -48,7 +47,7 @@ enum tpm_duration { ...@@ -48,7 +47,7 @@ enum tpm_duration {
static LIST_HEAD(tpm_chip_list); static LIST_HEAD(tpm_chip_list);
static DEFINE_SPINLOCK(driver_lock); static DEFINE_SPINLOCK(driver_lock);
static int dev_mask[TPM_NUM_MASK_ENTRIES]; static DECLARE_BITMAP(dev_mask, TPM_NUM_DEVICES);
/* /*
* Array with one entry per ordinal defining the maximum amount * Array with one entry per ordinal defining the maximum amount
...@@ -1038,8 +1037,7 @@ void tpm_remove_hardware(struct device *dev) ...@@ -1038,8 +1037,7 @@ void tpm_remove_hardware(struct device *dev)
sysfs_remove_group(&dev->kobj, chip->vendor.attr_group); sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
tpm_bios_log_teardown(chip->bios_dir); tpm_bios_log_teardown(chip->bios_dir);
dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES] &= clear_bit(chip->dev_num, dev_mask);
~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
kfree(chip); kfree(chip);
...@@ -1097,7 +1095,6 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend ...@@ -1097,7 +1095,6 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
char *devname; char *devname;
struct tpm_chip *chip; struct tpm_chip *chip;
int i, j;
/* Driver specific per-device data */ /* Driver specific per-device data */
chip = kzalloc(sizeof(*chip), GFP_KERNEL); chip = kzalloc(sizeof(*chip), GFP_KERNEL);
...@@ -1116,19 +1113,9 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend ...@@ -1116,19 +1113,9 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific)); memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
chip->dev_num = -1; chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
for (i = 0; i < TPM_NUM_MASK_ENTRIES; i++) if (chip->dev_num >= TPM_NUM_DEVICES) {
for (j = 0; j < 8 * sizeof(int); j++)
if ((dev_mask[i] & (1 << j)) == 0) {
chip->dev_num =
i * TPM_NUM_MASK_ENTRIES + j;
dev_mask[i] |= 1 << j;
goto dev_num_search_complete;
}
dev_num_search_complete:
if (chip->dev_num < 0) {
dev_err(dev, "No available tpm device numbers\n"); dev_err(dev, "No available tpm device numbers\n");
kfree(chip); kfree(chip);
return NULL; return NULL;
...@@ -1137,6 +1124,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend ...@@ -1137,6 +1124,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
else else
chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR; chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR;
set_bit(chip->dev_num, dev_mask);
devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL); devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
chip->vendor.miscdev.name = devname; chip->vendor.miscdev.name = devname;
...@@ -1150,8 +1139,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend ...@@ -1150,8 +1139,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
chip->vendor.miscdev.name, chip->vendor.miscdev.name,
chip->vendor.miscdev.minor); chip->vendor.miscdev.minor);
put_device(dev); put_device(dev);
clear_bit(chip->dev_num, dev_mask);
kfree(chip); kfree(chip);
dev_mask[i] &= !(1 << j);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment