diff mbox

arcmsr: Fix a potential data corruption issue

Message ID 1436505490-9640-1-git-send-email-christophe.jaillet@wanadoo.fr (mailing list archive)
State New, archived
Headers show

Commit Message

Christophe JAILLET July 10, 2015, 5:18 a.m. UTC
Resetting rqbuffer or wqbuffer must be done within a critial section
in order to avoir potential data corruption.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This change is *untested* because I don't have the corresponding hardware.
However, it should'nt have any evil side effect (just a few lines of code
moved from outside to within a spin_lock)

This just a "guess" based on the other uses of the 2 buffers within the
code.
It is also inspired on how things are done in arcmsr_hba.c
(see line #2390)

So please ignore if not relevant.
---
 drivers/scsi/arcmsr/arcmsr_attr.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Dan Carpenter July 10, 2015, 9:25 a.m. UTC | #1
On Fri, Jul 10, 2015 at 07:18:10AM +0200, Christophe JAILLET wrote:
> Resetting rqbuffer or wqbuffer must be done within a critial section
> in order to avoir potential data corruption.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

I don't know the code well enough to say if it's necessary, but it seems
reasonable to me.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c
index 9c86481..2ad970d 100644
--- a/drivers/scsi/arcmsr/arcmsr_attr.c
+++ b/drivers/scsi/arcmsr/arcmsr_attr.c
@@ -171,22 +171,21 @@  static ssize_t arcmsr_sysfs_iop_message_clear(struct file *filp,
 		return -EACCES;
 
 	arcmsr_clear_iop2drv_rqueue_buffer(acb);
-	acb->acb_flags |=
-		(ACB_F_MESSAGE_WQBUFFER_CLEARED
-		| ACB_F_MESSAGE_RQBUFFER_CLEARED
-		| ACB_F_MESSAGE_WQBUFFER_READED);
 	spin_lock_irqsave(&acb->rqbuffer_lock, flags);
+	acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED;
 	acb->rqbuf_getIndex = 0;
 	acb->rqbuf_putIndex = 0;
+	pQbuffer = acb->rqbuffer;
+	memset(pQbuffer, 0, sizeof (struct QBUFFER));
 	spin_unlock_irqrestore(&acb->rqbuffer_lock, flags);
 	spin_lock_irqsave(&acb->wqbuffer_lock, flags);
+	acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED |
+			   ACB_F_MESSAGE_WQBUFFER_READED);
 	acb->wqbuf_getIndex = 0;
 	acb->wqbuf_putIndex = 0;
-	spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
-	pQbuffer = acb->rqbuffer;
-	memset(pQbuffer, 0, sizeof (struct QBUFFER));
 	pQbuffer = acb->wqbuffer;
 	memset(pQbuffer, 0, sizeof (struct QBUFFER));
+	spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
 	return 1;
 }