# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1172852128 0
# Node ID bc265a79dd32d3776160766e7c542cc790fd0155
# Parent cc18ea7309b3f1a68a90041156e4cc177d78a006
tpm: Code style cleanups.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c | 166 ++++++++++--------------
1 files changed, 76 insertions(+), 90 deletions(-)
diff -r cc18ea7309b3 -r bc265a79dd32
linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c
--- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c Fri Mar 02 16:03:21
2007 +0000
+++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c Fri Mar 02 16:15:28
2007 +0000
@@ -113,14 +113,13 @@ void __exit tpmif_exit(void);
static inline int
-tx_buffer_copy(struct tx_buffer *txb, const u8 * src, int len,
+tx_buffer_copy(struct tx_buffer *txb, const u8 *src, int len,
int isuserbuffer)
{
int copied = len;
- if (len > txb->size) {
+ if (len > txb->size)
copied = txb->size;
- }
if (isuserbuffer) {
if (copy_from_user(txb->data, src, copied))
return -EFAULT;
@@ -133,18 +132,20 @@ tx_buffer_copy(struct tx_buffer *txb, co
static inline struct tx_buffer *tx_buffer_alloc(void)
{
- struct tx_buffer *txb = kzalloc(sizeof (struct tx_buffer),
- GFP_KERNEL);
-
- if (txb) {
- txb->len = 0;
- txb->size = PAGE_SIZE;
- txb->data = (unsigned char *)__get_free_page(GFP_KERNEL);
- if (txb->data == NULL) {
- kfree(txb);
- txb = NULL;
- }
- }
+ struct tx_buffer *txb;
+
+ txb = kzalloc(sizeof(struct tx_buffer), GFP_KERNEL);
+ if (!txb)
+ return NULL;
+
+ txb->len = 0;
+ txb->size = PAGE_SIZE;
+ txb->data = (unsigned char *)__get_free_page(GFP_KERNEL);
+ if (txb->data == NULL) {
+ kfree(txb);
+ txb = NULL;
+ }
+
return txb;
}
@@ -160,37 +161,41 @@ static inline void tx_buffer_free(struct
/**************************************************************
Utility function for the tpm_private structure
**************************************************************/
-static inline void tpm_private_init(struct tpm_private *tp)
+static void tpm_private_init(struct tpm_private *tp)
{
spin_lock_init(&tp->tx_lock);
init_waitqueue_head(&tp->wait_q);
atomic_set(&tp->refcnt, 1);
}
-static inline void tpm_private_put(void)
-{
- if ( atomic_dec_and_test(&my_priv->refcnt)) {
- tpmif_free_tx_buffers(my_priv);
- kfree(my_priv);
- my_priv = NULL;
- }
+static void tpm_private_put(void)
+{
+ if (!atomic_dec_and_test(&my_priv->refcnt))
+ return;
+
+ tpmif_free_tx_buffers(my_priv);
+ kfree(my_priv);
+ my_priv = NULL;
}
static struct tpm_private *tpm_private_get(void)
{
int err;
- if (!my_priv) {
- my_priv = kzalloc(sizeof(struct tpm_private), GFP_KERNEL);
- if (my_priv) {
- tpm_private_init(my_priv);
- err = tpmif_allocate_tx_buffers(my_priv);
- if (err < 0) {
- tpm_private_put();
- }
- }
- } else {
+
+ if (my_priv) {
atomic_inc(&my_priv->refcnt);
- }
+ return my_priv;
+ }
+
+ my_priv = kzalloc(sizeof(struct tpm_private), GFP_KERNEL);
+ if (!my_priv)
+ return NULL;
+
+ tpm_private_init(my_priv);
+ err = tpmif_allocate_tx_buffers(my_priv);
+ if (err < 0)
+ tpm_private_put();
+
return my_priv;
}
@@ -379,10 +384,8 @@ static int tpmfront_probe(struct xenbus_
return -ENOMEM;
tp->chip = init_vtpm(&dev->dev, &tvd, tp);
-
- if (IS_ERR(tp->chip)) {
+ if (IS_ERR(tp->chip))
return PTR_ERR(tp->chip);
- }
err = xenbus_scanf(XBT_NIL, dev->nodename,
"handle", "%i", &handle);
@@ -401,6 +404,7 @@ static int tpmfront_probe(struct xenbus_
tpm_private_put();
return err;
}
+
return 0;
}
@@ -417,7 +421,8 @@ static int tpmfront_suspend(struct xenbu
{
struct tpm_private *tp = tpm_private_from_dev(&dev->dev);
u32 ctr;
- /* lock, so no app can send */
+
+ /* Take the lock, preventing any application from sending. */
mutex_lock(&suspend_lock);
tp->is_suspended = 1;
@@ -425,19 +430,17 @@ static int tpmfront_suspend(struct xenbu
if ((ctr % 10) == 0)
printk("TPM-FE [INFO]: Waiting for outstanding "
"request.\n");
- /*
- * Wait for a request to be responded to.
- */
+ /* Wait for a request to be responded to. */
interruptible_sleep_on_timeout(&tp->wait_q, 100);
}
return 0;
}
-static int __tpmfront_suspend_cancel(struct tpm_private *tp)
+static int tpmfront_resume(struct tpm_private *tp)
{
tp->is_suspended = 0;
- /* unlock, so apps can send again */
+ /* Allow applications to send again. */
mutex_unlock(&suspend_lock);
return 0;
}
@@ -445,7 +448,7 @@ static int tpmfront_suspend_cancel(struc
static int tpmfront_suspend_cancel(struct xenbus_device *dev)
{
struct tpm_private *tp = tpm_private_from_dev(&dev->dev);
- return __tpmfront_suspend_cancel(tp);
+ return tpmfront_resume(tp);
}
static int tpmfront_resume(struct xenbus_device *dev)
@@ -520,9 +523,8 @@ static void tpmif_free_tx_buffers(struct
{
unsigned int i;
- for (i = 0; i < TPMIF_TX_RING_SIZE; i++) {
+ for (i = 0; i < TPMIF_TX_RING_SIZE; i++)
tx_buffer_free(tp->tx_buffers[i]);
- }
}
static void tpmif_rx_action(unsigned long priv)
@@ -542,9 +544,8 @@ static void tpmif_rx_action(unsigned lon
received = tx->size;
buffer = kmalloc(received, GFP_ATOMIC);
- if (NULL == buffer) {
+ if (!buffer)
goto exit;
- }
for (i = 0; i < TPMIF_TX_RING_SIZE && offset < received; i++) {
struct tx_buffer *txb = tp->tx_buffers[i];
@@ -553,9 +554,8 @@ static void tpmif_rx_action(unsigned lon
tx = &tp->tx->ring[i].req;
tocopy = tx->size;
- if (tocopy > PAGE_SIZE) {
+ if (tocopy > PAGE_SIZE)
tocopy = PAGE_SIZE;
- }
memcpy(&buffer[offset], txb->data, tocopy);
@@ -613,12 +613,13 @@ static int tpm_xmit(struct tpm_private *
struct tx_buffer *txb = tp->tx_buffers[i];
int copied;
- if (NULL == txb) {
+ if (!txb) {
DPRINTK("txb (i=%d) is NULL. buffers initilized?\n"
"Not transmitting anything!\n", i);
spin_unlock_irq(&tp->tx_lock);
return -EFAULT;
}
+
copied = tx_buffer_copy(txb, &buf[offset], count,
isuserbuffer);
if (copied < 0) {
@@ -630,25 +631,26 @@ static int tpm_xmit(struct tpm_private *
offset += copied;
tx = &tp->tx->ring[i].req;
-
tx->addr = virt_to_machine(txb->data);
tx->size = txb->len;
- DPRINTK("First 4 characters sent by TPM-FE are 0x%02x 0x%02x
0x%02x 0x%02x\n",
+ DPRINTK("First 4 characters sent by TPM-FE are "
+ "0x%02x 0x%02x 0x%02x 0x%02x\n",
txb->data[0],txb->data[1],txb->data[2],txb->data[3]);
- /* get the granttable reference for this page */
+ /* Get the granttable reference for this page. */
tx->ref = gnttab_claim_grant_reference(&gref_head);
-
- if (-ENOSPC == tx->ref) {
+ if (tx->ref == -ENOSPC) {
spin_unlock_irq(&tp->tx_lock);
- DPRINTK(" Grant table claim reference failed in func:%s
line:%d file:%s\n", __FUNCTION__, __LINE__, __FILE__);
+ DPRINTK("Grant table claim reference failed in "
+ "func:%s line:%d file:%s\n",
+ __FUNCTION__, __LINE__, __FILE__);
return -ENOSPC;
}
- gnttab_grant_foreign_access_ref( tx->ref,
- tp->backend_id,
- virt_to_mfn(txb->data),
- 0 /*RW*/);
+ gnttab_grant_foreign_access_ref(tx->ref,
+ tp->backend_id,
+ virt_to_mfn(txb->data),
+ 0 /*RW*/);
wmb();
}
@@ -666,15 +668,10 @@ static int tpm_xmit(struct tpm_private *
static void tpmif_notify_upperlayer(struct tpm_private *tp)
{
- /*
- * Notify upper layer about the state of the connection
- * to the BE.
- */
- if (tp->is_connected) {
- vtpm_vd_status(tp->chip, TPM_VD_STATUS_CONNECTED);
- } else {
- vtpm_vd_status(tp->chip, TPM_VD_STATUS_DISCONNECTED);
- }
+ /* Notify upper layer about the state of the connection to the BE. */
+ vtpm_vd_status(tp->chip, (tp->is_connected
+ ? TPM_VD_STATUS_CONNECTED
+ : TPM_VD_STATUS_DISCONNECTED));
}
@@ -685,18 +682,16 @@ static void tpmif_set_connected_state(st
* should disconnect - assumption is that we will resume
* The mutex keeps apps from sending.
*/
- if (is_connected == 0 && tp->is_suspended == 1) {
+ if (is_connected == 0 && tp->is_suspended == 1)
return;
- }
/*
* Unlock the mutex if we are connected again
* after being suspended - now resuming.
* This also removes the suspend state.
*/
- if (is_connected == 1 && tp->is_suspended == 1) {
- __tpmfront_suspend_cancel(tp);
- }
+ if (is_connected == 1 && tp->is_suspended == 1)
+ tpmfront_resume(tp);
if (is_connected != tp->is_connected) {
tp->is_connected = is_connected;
@@ -714,33 +709,24 @@ static void tpmif_set_connected_state(st
static int __init tpmif_init(void)
{
- long rc = 0;
struct tpm_private *tp;
if (is_initial_xendomain())
return -EPERM;
tp = tpm_private_get();
- if (!tp) {
- rc = -ENOMEM;
- goto failexit;
- }
+ if (!tp)
+ return -ENOMEM;
IPRINTK("Initialising the vTPM driver.\n");
- if ( gnttab_alloc_grant_references ( TPMIF_TX_RING_SIZE,
- &gref_head ) < 0) {
- rc = -EFAULT;
- goto gnttab_alloc_failed;
+ if (gnttab_alloc_grant_references(TPMIF_TX_RING_SIZE,
+ &gref_head) < 0) {
+ tpm_private_put();
+ return -EFAULT;
}
init_tpm_xenbus();
return 0;
-
-gnttab_alloc_failed:
- tpm_private_put();
-failexit:
-
- return (int)rc;
}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|