public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Orjan Friberg <of@flatfrog.com>
To: Joakim Tjernlund <joakim.tjernlund@transmode.se>
Cc: "linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Subject: Re: JFFS2 oops when writing to two partitions simultaneously
Date: Thu, 26 Jan 2012 13:51:30 +0100	[thread overview]
Message-ID: <4F214C52.5050300@flatfrog.com> (raw)
In-Reply-To: <OF515AA54C.99F179CF-ONC1257991.0040C6F9-C1257991.0041489F@transmode.se>

On 01/26/2012 12:53 PM, Joakim Tjernlund wrote:
> 			/* Allocating memory for output buffer if necessary */
> 			if ((this->compr_buf_size<  orig_slen)&&  (this->compr_buf)) {
> 				spin_unlock(&jffs2_compressor_list_lock);
>
> 				kfree(this->compr_buf);
> 				spin_lock(&jffs2_compressor_list_lock);
> 				this->compr_buf_size=0;
> 				this->compr_buf=NULL;
> 			}
>
> if 2 threads are competing here, I don't think you can drop the spin lock
> temporarily as this routine do.

Agreed.  Both the freeing of this->compr_buf and the usage of it when 
calling the compressor looks weird (because another process holding the 
lock could decide that the buffer is too small and allocate a new one):

    spin_unlock(&jffs2_compressor_list_lock);
    *datalen  = orig_slen;
    *cdatalen = orig_dlen;
    compr_ret = this->compress(data_in, this->compr_buf, datalen, cdatalen);
    spin_lock(&jffs2_compressor_list_lock);


I'm not sure I'm crazy about the allocation either, come to think of it:

if (!this->compr_buf) {
	spin_unlock(&jffs2_compressor_list_lock);
	tmp_buf = kmalloc(orig_slen, GFP_KERNEL);
	spin_lock(&jffs2_compressor_list_lock);
	if (!tmp_buf) {
		printk(KERN_WARNING "JFFS2: No memory for compressor allocation. (%d 
bytes)\n", orig_slen);
		continue;
	}
	else {
		this->compr_buf = tmp_buf;
		this->compr_buf_size = orig_slen;
	}
}

Even though we hold the lock when assigning the new buffer, things could 
have been changed while we're doing the kmalloc.  In this case, maybe 
just dropping the unlock/lock and allocating with GFP_ATOMIC would solve it.

I'm not sure I see why compr_buf has to belong to the compressor.  To 
not have to kmalloc a buffer each and every time?

-- 
Orjan Friberg
FlatFrog Laboratories AB

  reply	other threads:[~2012-01-26 12:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-24  9:55 JFFS2 oops when writing to two partitions simultaneously Orjan Friberg
2012-01-24 17:15 ` Orjan Friberg
2012-01-24 19:02   ` Orjan Friberg
2012-01-25 19:53     ` Orjan Friberg
2012-01-25 21:01       ` Orjan Friberg
2012-01-26  8:19         ` Joakim Tjernlund
2012-01-26  9:02           ` Orjan Friberg
2012-01-26  9:53             ` Joakim Tjernlund
2012-01-26  9:02         ` Orjan Friberg
2012-01-26 11:53           ` Joakim Tjernlund
2012-01-26 12:51             ` Orjan Friberg [this message]
2012-01-26 13:16               ` Joakim Tjernlund
2012-01-26 14:07                 ` Orjan Friberg
2012-01-26 14:23                   ` Joakim Tjernlund
2012-01-26 14:53                     ` Orjan Friberg
2012-01-26 15:17                       ` Joakim Tjernlund
2012-01-26 15:25                         ` Orjan Friberg
2012-01-26 16:05                           ` Orjan Friberg
2012-01-26 16:17                             ` Joakim Tjernlund
2012-01-26 14:52                   ` Joakim Tjernlund
2012-01-26 15:09                     ` Joakim Tjernlund
2012-01-26 15:18                       ` Orjan Friberg

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=4F214C52.5050300@flatfrog.com \
    --to=of@flatfrog.com \
    --cc=joakim.tjernlund@transmode.se \
    --cc=linux-mtd@lists.infradead.org \
    /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