From: Kylene Jo Hall <kjhall@us.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
TPM Device Driver List <tpmdd-devel@lists.sourceforge.net>
Subject: [PATCH] tpm: use find_first_zero_bit
Date: Wed, 12 Apr 2006 16:47:59 -0500 [thread overview]
Message-ID: <1144878479.12054.91.camel@localhost.localdomain> (raw)
In-Reply-To: <20060411160206.4bffa1c2.akpm@osdl.org>
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 <kjhall@us.ibm.com>
---
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;
}
prev parent reply other threads:[~2006-04-12 21:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-10 14:37 [PATCH 3/7] tpm: chip struct update Kylene Jo Hall
2006-04-10 21:50 ` Andrew Morton
2006-04-11 22:42 ` [PATCH] tpm: use clear_bit Kylene Jo Hall
2006-04-11 23:02 ` Andrew Morton
2006-04-11 23:21 ` Andrew Morton
2006-04-12 21:47 ` Kylene Jo Hall [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1144878479.12054.91.camel@localhost.localdomain \
--to=kjhall@us.ibm.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tpmdd-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®