All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sylwester Nawrocki <s.nawrocki-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
To: Tushar Behera <trblinux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Kukjin Kim <kgene-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	padma.v-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
	drake-6IF/jdPJHihWk0Htik3J/w@public.gmane.org,
	Kim Sangbeom <sbkim73-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Linux-ALSA <alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org>,
	ML Devicetree
	<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-samsung-soc
	<linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	ML Arch-Arm
	<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Subject: Re: [PATCH V3 09/15] ASoC: samsung: i2s: Protect more registers with a spinlock
Date: Mon, 19 Jan 2015 13:28:50 +0100	[thread overview]
Message-ID: <54BCF882.10005@samsung.com> (raw)
In-Reply-To: <CAC5m3BxTkS3KtwUC6itMRF=545PoWJw1gYV6av3p7QjtVMFXTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Hi Tuashar,

On 17/01/15 06:21, Tushar Behera wrote:
> On Thu, Jan 15, 2015 at 3:42 AM, Sylwester Nawrocki
> <s.nawrocki-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> wrote:
>> Ensure the I2SMOD, I2SPSR registers, which are also exposed through
>> clk API are only accessed with the i2s->spinlock spinlock held.
>>
>> Signed-off-by: Sylwester Nawrocki <s.nawrocki-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
>> ---
>>  sound/soc/samsung/i2s.c |   81 +++++++++++++++++++++++++++++------------------
>>  1 file changed, 51 insertions(+), 30 deletions(-)
>>
>> diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
>> index 20cc51f..05fc2f0 100644
>> --- a/sound/soc/samsung/i2s.c
>> +++ b/sound/soc/samsung/i2s.c
>> @@ -472,17 +472,22 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
>>  {
>>         struct i2s_dai *i2s = to_info(dai);
>>         struct i2s_dai *other = get_other_dai(i2s);
>> -       u32 mod = readl(i2s->addr + I2SMOD);
>>         const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
>>         unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
>>         unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
>> +       u32 mod, mask, val = 0;
>> +
>> +       spin_lock(i2s->lock);
>> +       mod = readl(i2s->addr + I2SMOD);
>> +       spin_unlock(i2s->lock);
>>
> 
> 'mod' is now updated only at the bottom of this function. The above
> readl can be omitted.

mod is used in some of the 'if' statements below, so we must read it
here beforehand.

>>         switch (clk_id) {
>>         case SAMSUNG_I2S_OPCLK:
>> -               mod &= ~MOD_OPCLK_MASK;
>> -               mod |= dir;
>> +               mask = MOD_OPCLK_MASK;
>> +               val = dir;
>>                 break;
>>         case SAMSUNG_I2S_CDCLK:
>> +               mask = 1 << i2s_regs->cdclkcon_off;
> 
> Use BIT() macro instead?

Yes, it would be a good code cleanup, might be worth to include it in
some future patch series. I'll keep it in mind, since this patch is merged
already.
And the logical bit operations is one of things people make mistakes most
often, so any changes like these would need to be well tested and/or
carefully reviewed.

--
Thanks,
Sylwester
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: s.nawrocki@samsung.com (Sylwester Nawrocki)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V3 09/15] ASoC: samsung: i2s: Protect more registers with a spinlock
Date: Mon, 19 Jan 2015 13:28:50 +0100	[thread overview]
Message-ID: <54BCF882.10005@samsung.com> (raw)
In-Reply-To: <CAC5m3BxTkS3KtwUC6itMRF=545PoWJw1gYV6av3p7QjtVMFXTQ@mail.gmail.com>

Hi Tuashar,

On 17/01/15 06:21, Tushar Behera wrote:
> On Thu, Jan 15, 2015 at 3:42 AM, Sylwester Nawrocki
> <s.nawrocki@samsung.com> wrote:
>> Ensure the I2SMOD, I2SPSR registers, which are also exposed through
>> clk API are only accessed with the i2s->spinlock spinlock held.
>>
>> Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
>> ---
>>  sound/soc/samsung/i2s.c |   81 +++++++++++++++++++++++++++++------------------
>>  1 file changed, 51 insertions(+), 30 deletions(-)
>>
>> diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
>> index 20cc51f..05fc2f0 100644
>> --- a/sound/soc/samsung/i2s.c
>> +++ b/sound/soc/samsung/i2s.c
>> @@ -472,17 +472,22 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
>>  {
>>         struct i2s_dai *i2s = to_info(dai);
>>         struct i2s_dai *other = get_other_dai(i2s);
>> -       u32 mod = readl(i2s->addr + I2SMOD);
>>         const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
>>         unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
>>         unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
>> +       u32 mod, mask, val = 0;
>> +
>> +       spin_lock(i2s->lock);
>> +       mod = readl(i2s->addr + I2SMOD);
>> +       spin_unlock(i2s->lock);
>>
> 
> 'mod' is now updated only at the bottom of this function. The above
> readl can be omitted.

mod is used in some of the 'if' statements below, so we must read it
here beforehand.

>>         switch (clk_id) {
>>         case SAMSUNG_I2S_OPCLK:
>> -               mod &= ~MOD_OPCLK_MASK;
>> -               mod |= dir;
>> +               mask = MOD_OPCLK_MASK;
>> +               val = dir;
>>                 break;
>>         case SAMSUNG_I2S_CDCLK:
>> +               mask = 1 << i2s_regs->cdclkcon_off;
> 
> Use BIT() macro instead?

Yes, it would be a good code cleanup, might be worth to include it in
some future patch series. I'll keep it in mind, since this patch is merged
already.
And the logical bit operations is one of things people make mistakes most
often, so any changes like these would need to be well tested and/or
carefully reviewed.

--
Thanks,
Sylwester

  parent reply	other threads:[~2015-01-19 12:28 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14 18:42 [PATCH V3 00/15] ASoC: samsung: Add clk provider for I2S internal clocks Sylwester Nawrocki
2015-01-14 18:42 ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 01/15] ASoC: samsung: i2s: samsung_i2s_get_driver_data() cleanup Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 02/15] ASoC: samsung: i2s: Add return value checks in probe() Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 03/15] ASoC: samsung: i2s: Request memory region in driver probe() Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 04/15] ASoC: samsung: i2s: Move clk_get() to platform " Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 05/15] ASoC: samsung: i2s: Move clk enable to the " Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 06/15] ASoC: samsung: i2s: Add get_other_dai helper function Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 07/15] ASoC: samsung: i2s: Remove an unneeded goto usage Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 08/15] ASoC: samsung: i2s: Add spinlock in place of local_irq_* calls Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 09/15] ASoC: samsung: i2s: Protect more registers with a spinlock Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-17  5:21   ` Tushar Behera
2015-01-17  5:21     ` Tushar Behera
     [not found]     ` <CAC5m3BxTkS3KtwUC6itMRF=545PoWJw1gYV6av3p7QjtVMFXTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-19 12:28       ` Sylwester Nawrocki [this message]
2015-01-19 12:28         ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 10/15] ASoC: samsung: odroidx2: Handle I2S CDCLK clock conditionally Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 11/15] ASoC: samsung: i2s: Add clk provider DT binding documentation Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 12/15] ASoC: samsung: i2s: Add clock provider for the I2S internal clocks Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 13/15] ARM: dts: Exynos4 and Odroid X2/U3 sound device nodes update Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 19:54   ` Mark Brown
2015-01-14 19:54     ` Mark Brown
     [not found]     ` <20150114195452.GM3043-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-02-03  4:27       ` Kukjin Kim
2015-02-03  4:27         ` Kukjin Kim
2015-02-03 11:04         ` Sylwester Nawrocki
2015-02-03 11:04           ` Sylwester Nawrocki
     [not found]           ` <54D0AB30.2010504-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-02-03 13:11             ` Mark Brown
2015-02-03 13:11               ` Mark Brown
2015-02-03 14:05               ` Sylwester Nawrocki
2015-02-03 14:05                 ` Sylwester Nawrocki
2015-02-03 16:19                 ` Mark Brown
2015-02-03 16:19                   ` Mark Brown
2015-01-14 18:42 ` [PATCH V3 14/15] ARM: dts: Switch Odroid X2/U2 to simple-audio-card Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 18:42 ` [PATCH V3 15/15] ARM: dts: Fix I2S1, I2S2 compatible for exynos4 SoCs Sylwester Nawrocki
2015-01-14 18:42   ` Sylwester Nawrocki
2015-01-14 19:49 ` [PATCH V3 00/15] ASoC: samsung: Add clk provider for I2S internal clocks Mark Brown
2015-01-14 19:49   ` Mark Brown

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=54BCF882.10005@samsung.com \
    --to=s.nawrocki-sze3o3uu22jbdgjk7y7tuq@public.gmane.org \
    --cc=alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=drake-6IF/jdPJHihWk0Htik3J/w@public.gmane.org \
    --cc=kgene-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=padma.v-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=sbkim73-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=trblinux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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 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.