diff mbox

[1/3] dma: mv_xor: take channel spinlock in mv_xor_status()

Message ID 1388144314-1581-2-git-send-email-thomas.petazzoni@free-electrons.com (mailing list archive)
State Changes Requested
Delegated to: Dan Williams
Headers show

Commit Message

Thomas Petazzoni Dec. 27, 2013, 11:38 a.m. UTC
The mv_xor_status() function accesses the mv_xor_chan structure, but
was not taking the corresponding spinlock. This patch fixes this
problem.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 drivers/dma/mv_xor.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Andy Shevchenko Dec. 30, 2013, 9:55 a.m. UTC | #1
T24gRnJpLCAyMDEzLTEyLTI3IGF0IDEyOjM4ICswMTAwLCBUaG9tYXMgUGV0YXp6b25pIHdyb3Rl
Og0KPiBUaGUgbXZfeG9yX3N0YXR1cygpIGZ1bmN0aW9uIGFjY2Vzc2VzIHRoZSBtdl94b3JfY2hh
biBzdHJ1Y3R1cmUsIGJ1dA0KPiB3YXMgbm90IHRha2luZyB0aGUgY29ycmVzcG9uZGluZyBzcGlu
bG9jay4gVGhpcyBwYXRjaCBmaXhlcyB0aGlzDQo+IHByb2JsZW0uDQo+IA0KPiBTaWduZWQtb2Zm
LWJ5OiBUaG9tYXMgUGV0YXp6b25pIDx0aG9tYXMucGV0YXp6b25pQGZyZWUtZWxlY3Ryb25zLmNv
bT4NCj4gLS0tDQo+ICBkcml2ZXJzL2RtYS9tdl94b3IuYyB8IDEwICsrKysrKysrLS0NCj4gIDEg
ZmlsZSBjaGFuZ2VkLCA4IGluc2VydGlvbnMoKyksIDIgZGVsZXRpb25zKC0pDQo+IA0KPiBkaWZm
IC0tZ2l0IGEvZHJpdmVycy9kbWEvbXZfeG9yLmMgYi9kcml2ZXJzL2RtYS9tdl94b3IuYw0KPiBp
bmRleCA1M2ZiMGM4Li41MjZhYjI3IDEwMDY0NA0KPiAtLS0gYS9kcml2ZXJzL2RtYS9tdl94b3Iu
Yw0KPiArKysgYi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oYW4s
IGNvb2tpZSwgdHhzdGF0ZSk7DQo+ICsJc3Bpbl91bmxvY2tfYmgoJm12X2NoYW4tPmxvY2spOw0K
PiArDQo+ICsJcmV0dXJuIHJldDsNCj4gIH0NCj4gIA0KPiAgc3RhdGljIHZvaWQgbXZfZHVtcF94
b3JfcmVncyhzdHJ1Y3QgbXZfeG9yX2NoYW4gKmNoYW4pDQoNCi0tIA0KQW5keSBTaGV2Y2hlbmtv
IDxhbmRyaXkuc2hldmNoZW5rb0BpbnRlbC5jb20+DQpJbnRlbCBGaW5sYW5kIE95DQotLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0KSW50ZWwgRmlubGFuZCBPeQpSZWdpc3RlcmVkIEFkZHJlc3M6IFBMIDI4MSwgMDAxODEg
SGVsc2lua2kgCkJ1c2luZXNzIElkZW50aXR5IENvZGU6IDAzNTc2MDYgLSA0IApEb21pY2lsZWQg
aW4gSGVsc2lua2kgCgpUaGlzIGUtbWFpbCBhbmQgYW55IGF0dGFjaG1lbnRzIG1heSBjb250YWlu
IGNvbmZpZGVudGlhbCBtYXRlcmlhbCBmb3IKdGhlIHNvbGUgdXNlIG9mIHRoZSBpbnRlbmRlZCBy
ZWNpcGllbnQocykuIEFueSByZXZpZXcgb3IgZGlzdHJpYnV0aW9uCmJ5IG90aGVycyBpcyBzdHJp
Y3RseSBwcm9oaWJpdGVkLiBJZiB5b3UgYXJlIG5vdCB0aGUgaW50ZW5kZWQKcmVjaXBpZW50LCBw
bGVhc2UgY29udGFjdCB0aGUgc2VuZGVyIGFuZCBkZWxldGUgYWxsIGNvcGllcy4K

--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Williams Dec. 31, 2013, 10:48 p.m. UTC | #2
On Fri, Dec 27, 2013 at 3:38 AM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> The mv_xor_status() function accesses the mv_xor_chan structure, but
> was not taking the corresponding spinlock. This patch fixes this
> problem.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
>  drivers/dma/mv_xor.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
> index 53fb0c8..526ab27 100644
> --- a/drivers/dma/mv_xor.c
> +++ b/drivers/dma/mv_xor.c
> @@ -701,14 +701,20 @@ static enum dma_status mv_xor_status(struct dma_chan *chan,
>         struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
>         enum dma_status ret;
>
> +       spin_lock_bh(&mv_chan->lock);
> +
>         ret = dma_cookie_status(chan, cookie, txstate);
>         if (ret == DMA_COMPLETE) {
>                 mv_xor_clean_completed_slots(mv_chan);

I think you can just delete this call to
mv_xor_clean_completed_slots().  The fact that the descriptors are
complete means that __mv_xor_slot_cleanup ran, and if that is the case
there should be nothing to cleanup.

--
Dan
--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ezequiel Garcia March 7, 2014, 3:51 p.m. UTC | #3
Hello Dan,

Thomas is a bit busy right now, so I'm picking this where he left it.

On Dec 31, Dan Williams wrote:
> On Fri, Dec 27, 2013 at 3:38 AM, Thomas Petazzoni
> <thomas.petazzoni@free-electrons.com> wrote:
[..]
> > @@ -701,14 +701,20 @@ static enum dma_status mv_xor_status(struct dma_chan *chan,
> >         struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
> >         enum dma_status ret;
> >
> > +       spin_lock_bh(&mv_chan->lock);
> > +
> >         ret = dma_cookie_status(chan, cookie, txstate);
> >         if (ret == DMA_COMPLETE) {
> >                 mv_xor_clean_completed_slots(mv_chan);
> 
> I think you can just delete this call to
> mv_xor_clean_completed_slots().  The fact that the descriptors are
> complete means that __mv_xor_slot_cleanup ran, and if that is the case
> there should be nothing to cleanup.
> 

In that case, we don't need to take the lock anywhere in this function:

1. It's not needed for dma_cookie_status() (as per Andy's comment).
2. It's not needed for mv_xor_slot_cleanup(), which takes the lock.
diff mbox

Patch

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 53fb0c8..526ab27 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -701,14 +701,20 @@  static enum dma_status mv_xor_status(struct dma_chan *chan,
 	struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
 	enum dma_status ret;
 
+	spin_lock_bh(&mv_chan->lock);
+
 	ret = dma_cookie_status(chan, cookie, txstate);
 	if (ret == DMA_COMPLETE) {
 		mv_xor_clean_completed_slots(mv_chan);
+		spin_unlock_bh(&mv_chan->lock);
 		return ret;
 	}
-	mv_xor_slot_cleanup(mv_chan);
+	__mv_xor_slot_cleanup(mv_chan);
 
-	return dma_cookie_status(chan, cookie, txstate);
+	ret = dma_cookie_status(chan, cookie, txstate);
+	spin_unlock_bh(&mv_chan->lock);
+
+	return ret;
 }
 
 static void mv_dump_xor_regs(struct mv_xor_chan *chan)