[PATCH] tpm: use find_first_zero_bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2006-04-11 at 16:02 -0700, Andrew Morton wrote:
> -			}
> +	/* This should use find_first_zero_bit() */
> +	for (dev_num = 0; dev_num < TPM_NUM_DEVICES; dev_num++) {

Given the suggestion in the code of your use-clear_bit-fix.  This patch
uses find_first_zero_bit to find a bit instead of the roll my own for
loop solution.

Signed-off-by: Kylie Hall <[email protected]>
---
 drivers/char/tpm/tpm.c |   20 ++++++--------------
 1 files changed, 6 insertions(+), 14 deletions(-)

--- linux-2.6.17-rc1-mm2/drivers/char/tpm/tpm.c	2006-04-12 11:46:18.375300250 -0500
+++ linux-2.6.17-rc1/drivers/char/tpm/tpm.c	2006-04-12 12:34:41.692746250 -0500
@@ -1090,7 +1090,6 @@ struct tpm_chip *tpm_register_hardware(s
 
 	char *devname;
 	struct tpm_chip *chip;
-	int dev_num;
 
 	/* Driver specific per-device data */
 	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
@@ -1109,18 +1108,9 @@ struct tpm_chip *tpm_register_hardware(s
 
 	memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
 
-	chip->dev_num = -1;
-
-	/* This should use find_first_zero_bit() */
-	for (dev_num = 0; dev_num < TPM_NUM_DEVICES; dev_num++) {
-		if (!test_bit(dev_num, dev_mask)) {
-			chip->dev_num = dev_num;
-			set_bit(dev_num, dev_mask);
-			break;
-		}
-	}
-
-	if (chip->dev_num < 0) {
+	chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
+	
+	if (chip->dev_num < 0 || chip->dev_num > TPM_NUM_DEVICES) {
 		dev_err(dev, "No available tpm device numbers\n");
 		kfree(chip);
 		return NULL;
@@ -1129,6 +1119,8 @@ struct tpm_chip *tpm_register_hardware(s
 	else
 		chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR;
 
+	set_bit(chip->dev_num, dev_mask);
+
 	devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
 	scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
 	chip->vendor.miscdev.name = devname;
@@ -1143,7 +1135,7 @@ struct tpm_chip *tpm_register_hardware(s
 			chip->vendor.miscdev.minor);
 		put_device(dev);
 		kfree(chip);
-		clear_bit(dev_num, dev_mask);
+		clear_bit(chip->dev_num, dev_mask);
 		return NULL;
 	}
 


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux