All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
To: Jarkko Nikula <jhnikula@gmail.com>
Cc: Tony Lindgren <tony@atomide.com>,
	Peter Ujfalusi <peter.ujfalusi@nokia.com>,
	linux-omap@vger.kernel.org
Subject: [PATCH] OMAP: McBSP: Fix possible port lockout
Date: Wed, 16 Dec 2009 17:16:28 +0100	[thread overview]
Message-ID: <200912161716.30041.jkrzyszt@tis.icnet.pl> (raw)

In its current form, the omap_mcbsp_request() function can return after 
irq_request() failure without any cleanups, effectively locking out the port 
forever with clocks left running. Fix it.

Signed-off-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>

---
Wednesday 16 December 2009 09:12:55 Jarkko Nikula napisał(a):
> On Tue, 15 Dec 2009 01:36:47 +0100
> Janusz Krzysztofik <jkrzyszt@tis.icnet.pl> wrote:
> > 3. In omap_mcbsp_free(), marking the port as free before deallocating the
> >    cache, could result in memory leak as well.
> >
> > I hope all are addressed correctly. Since releasing the port with
> >
> > 	mcbsp->free = 1;
> >
> > after kzalloc() failure should be atomic, I have assumed this doesn't
> > require locking.
>
> Good catch. One comment below.
>
> > @@ -471,6 +491,9 @@ void omap_mcbsp_free(unsigned int id)
> >  		free_irq(mcbsp->tx_irq, (void *)mcbsp);
> >  	}
> >
> > +	kfree(mcbsp->reg_cache);
> > +	mcbsp->reg_cache = NULL;
> > +
> >  	spin_lock(&mcbsp->lock);
> >  	if (mcbsp->free) {
> >  		dev_err(mcbsp->dev, "McBSP%d was not reserved\n",
>
> This is fine in current form but to play safe, lets do the kfree
> inside the spin_lock section where the mcbsp->free is set. Then there
> is no risk if some future code would use the mcbsp->free as a guard for
> cache etc. access.

Jarkko,

More and more looking at this, I think that omap_mcbsp_request() should be 
cleaned up frist in respect of freeing resources on error before we put any 
new functionality there.

This patch could be either joined with patch 1/5 or introduced as extra patch 
1.5/5 into the McBSP caching set if not accepted as a separate fix.

I'm not sure if it is really required to revert any  
mcbsp->pdata->ops->request() or omap34xx_mcbsp_request() applied changes by 
calling mcbsp->pdata->ops->free() or omap34xx_mcbsp_free() from here.

Thanks,
Janusz


diff -upr git.orig/arch/arm/plat-omap/mcbsp.c git/arch/arm/plat-omap/mcbsp.c
--- git.orig/arch/arm/plat-omap/mcbsp.c	2009-12-16 16:33:16.000000000 +0100
+++ git/arch/arm/plat-omap/mcbsp.c	2009-12-16 16:32:50.000000000 +0100
@@ -436,7 +436,7 @@ int omap_mcbsp_request(unsigned int id)
 			dev_err(mcbsp->dev, "Unable to request TX IRQ %d "
 					"for McBSP%d\n", mcbsp->tx_irq,
 					mcbsp->id);
-			return err;
+			goto error;
 		}
 
 		init_completion(&mcbsp->rx_irq_completion);
@@ -446,12 +446,26 @@ int omap_mcbsp_request(unsigned int id)
 			dev_err(mcbsp->dev, "Unable to request RX IRQ %d "
 					"for McBSP%d\n", mcbsp->rx_irq,
 					mcbsp->id);
-			free_irq(mcbsp->tx_irq, (void *)mcbsp);
-			return err;
+			goto tx_irq;
 		}
 	}
 
 	return 0;
+tx_irq:
+	free_irq(mcbsp->tx_irq, (void *)mcbsp);
+error:
+	if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
+			mcbsp->pdata->ops->free(id);
+
+	/* Do procedure specific to omap34xx arch, if applicable */
+	omap34xx_mcbsp_free(mcbsp);
+
+	clk_disable(mcbsp->fclk);
+	clk_disable(mcbsp->iclk);
+
+	mcbsp->free = 1;
+
+	return err;
 }
 EXPORT_SYMBOL(omap_mcbsp_request);
 
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2009-12-16 16:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-16 16:16 Janusz Krzysztofik [this message]
2009-12-17  7:19 ` [PATCH] OMAP: McBSP: Fix possible port lockout Jarkko Nikula
2009-12-17  9:06 ` Peter Ujfalusi

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=200912161716.30041.jkrzyszt@tis.icnet.pl \
    --to=jkrzyszt@tis.icnet.pl \
    --cc=jhnikula@gmail.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=peter.ujfalusi@nokia.com \
    --cc=tony@atomide.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.