ia64/xen-unstable
changeset 8622:9f2c47ae2b86
sanitize tpmfront. missing spin_unlock'ing in error paths and fix coding style.
Signed-off-by: Vincent Hanquez <vincent@xensource.com>
Signed-off-by: Vincent Hanquez <vincent@xensource.com>
author | vhanquez@kneesa.uk.xensource.com |
---|---|
date | Mon Jan 16 23:43:58 2006 +0000 (2006-01-16) |
parents | f1fc94516c4c |
children | 6ce7c026320e |
files | linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c |
line diff
1.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c Mon Jan 16 22:11:43 2006 +0000 1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c Mon Jan 16 23:43:58 2006 +0000 1.3 @@ -90,11 +90,8 @@ tx_buffer_copy(struct tx_buffer *txb, co 1.4 copied = txb->size; 1.5 } 1.6 if (isuserbuffer) { 1.7 - if (copy_from_user(txb->data, 1.8 - src, 1.9 - copied)) { 1.10 + if (copy_from_user(txb->data, src, copied)) 1.11 return -EFAULT; 1.12 - } 1.13 } else { 1.14 memcpy(txb->data, src, copied); 1.15 } 1.16 @@ -184,15 +181,12 @@ EXPORT_SYMBOL(tpm_fe_unregister_receiver 1.17 static int tpm_fe_send_upperlayer(const u8 * buf, size_t count, 1.18 const void *ptr) 1.19 { 1.20 - int rc; 1.21 + int rc = 0; 1.22 1.23 down(&upperlayer_lock); 1.24 1.25 - if (upperlayer_tpmfe && upperlayer_tpmfe->receive) { 1.26 + if (upperlayer_tpmfe && upperlayer_tpmfe->receive) 1.27 rc = upperlayer_tpmfe->receive(buf, count, ptr); 1.28 - } else { 1.29 - rc = 0; 1.30 - } 1.31 1.32 up(&upperlayer_lock); 1.33 return rc; 1.34 @@ -242,7 +236,7 @@ fail: 1.35 static void destroy_tpmring(struct tpmfront_info *info, struct tpm_private *tp) 1.36 { 1.37 tpmif_set_connected_state(tp, 0); 1.38 - if ( tp->tx != NULL ) { 1.39 + if (tp->tx != NULL) { 1.40 gnttab_end_foreign_access(info->ring_ref, 0, 1.41 (unsigned long)tp->tx); 1.42 tp->tx = NULL; 1.43 @@ -397,20 +391,19 @@ static int 1.44 tpmfront_suspend(struct xenbus_device *dev) 1.45 { 1.46 struct tpm_private *tp = &my_private; 1.47 - u32 ctr = 0; 1.48 + u32 ctr; 1.49 1.50 /* lock, so no app can send */ 1.51 down(&suspend_lock); 1.52 tp->is_suspended = 1; 1.53 1.54 - while (atomic_read(&tp->tx_busy) && ctr <= 25) { 1.55 + for (ctr = 0; atomic_read(&tp->tx_busy) && ctr <= 25; ctr++) { 1.56 if ((ctr % 10) == 0) 1.57 printk("TPM-FE [INFO]: Waiting for outstanding request.\n"); 1.58 /* 1.59 * Wait for a request to be responded to. 1.60 */ 1.61 interruptible_sleep_on_timeout(&tp->wait_q, 100); 1.62 - ctr++; 1.63 } 1.64 1.65 if (atomic_read(&tp->tx_busy)) { 1.66 @@ -428,16 +421,13 @@ static int 1.67 tpmfront_resume(struct xenbus_device *dev) 1.68 { 1.69 struct tpmfront_info *info = dev->data; 1.70 - int err = talk_to_backend(dev, info); 1.71 - 1.72 - 1.73 - return err; 1.74 + return talk_to_backend(dev, info); 1.75 } 1.76 1.77 static void 1.78 tpmif_connect(u16 evtchn, domid_t domid) 1.79 { 1.80 - int err = 0; 1.81 + int err; 1.82 struct tpm_private *tp = &my_private; 1.83 1.84 tp->evtchn = evtchn; 1.85 @@ -481,12 +471,8 @@ tpm_allocate_buffers(struct tpm_private 1.86 { 1.87 unsigned int i; 1.88 1.89 - i = 0; 1.90 - while (i < TPMIF_TX_RING_SIZE) { 1.91 + for (i = 0; i < TPMIF_TX_RING_SIZE; i++) 1.92 tp->tx_buffers[i] = tx_buffer_alloc(); 1.93 - i++; 1.94 - } 1.95 - 1.96 return 1; 1.97 } 1.98 1.99 @@ -509,9 +495,7 @@ tpmif_rx_action(unsigned long unused) 1.100 goto exit; 1.101 } 1.102 1.103 - i = 0; 1.104 - while (i < TPMIF_TX_RING_SIZE && 1.105 - offset < received) { 1.106 + for (i = 0; i < TPMIF_TX_RING_SIZE && offset < received; i++) { 1.107 struct tx_buffer *txb = tp->tx_buffers[i]; 1.108 tpmif_tx_request_t *tx; 1.109 unsigned int tocopy; 1.110 @@ -527,7 +511,6 @@ tpmif_rx_action(unsigned long unused) 1.111 gnttab_release_grant_reference(&gref_head, tx->ref); 1.112 1.113 offset += tocopy; 1.114 - i++; 1.115 } 1.116 1.117 tpm_fe_send_upperlayer(buffer, received, tp->tx_remember); 1.118 @@ -576,14 +559,13 @@ tpm_xmit(struct tpm_private *tp, 1.119 return -EIO; 1.120 } 1.121 1.122 - i = 0; 1.123 - while (count > 0 && i < TPMIF_TX_RING_SIZE) { 1.124 + for (i = 0; count > 0 && i < TPMIF_TX_RING_SIZE; i++) { 1.125 struct tx_buffer *txb = tp->tx_buffers[i]; 1.126 int copied; 1.127 1.128 if (NULL == txb) { 1.129 - DPRINTK("txb (i=%d) is NULL. buffers initilized?\n", i); 1.130 - DPRINTK("Not transmitting anything!\n"); 1.131 + DPRINTK("txb (i=%d) is NULL. buffers initilized?\n" 1.132 + "Not transmitting anything!\n", i); 1.133 spin_unlock_irq(&tp->tx_lock); 1.134 return -EFAULT; 1.135 } 1.136 @@ -591,6 +573,7 @@ tpm_xmit(struct tpm_private *tp, 1.137 isuserbuffer); 1.138 if (copied < 0) { 1.139 /* An error occurred */ 1.140 + spin_unlock_irq(&tp->tx_lock); 1.141 return copied; 1.142 } 1.143 count -= copied; 1.144 @@ -606,9 +589,10 @@ tpm_xmit(struct tpm_private *tp, 1.145 txb->data[0],txb->data[1],txb->data[2],txb->data[3]); 1.146 1.147 /* get the granttable reference for this page */ 1.148 - tx->ref = gnttab_claim_grant_reference( &gref_head ); 1.149 + tx->ref = gnttab_claim_grant_reference(&gref_head); 1.150 1.151 - if(-ENOSPC == tx->ref ) { 1.152 + if (-ENOSPC == tx->ref) { 1.153 + spin_unlock_irq(&tp->tx_lock); 1.154 DPRINTK(" Grant table claim reference failed in func:%s line:%d file:%s\n", __FUNCTION__, __LINE__, __FILE__); 1.155 return -ENOSPC; 1.156 } 1.157 @@ -616,7 +600,6 @@ tpm_xmit(struct tpm_private *tp, 1.158 tp->backend_id, 1.159 (tx->addr >> PAGE_SHIFT), 1.160 0 /*RW*/); 1.161 - i++; 1.162 wmb(); 1.163 } 1.164