From: Seung-Woo Kim <sw0312.kim@samsung.com>
To: Jaehoon Chung <jh80.chung@samsung.com>
Cc: ulf.hansson@linaro.org, linux-mmc@vger.kernel.org,
linux-kernel@vger.kernel.org,
Seung-Woo Kim <sw0312.kim@samsung.com>
Subject: Re: [PATCH] mmc: dw_mmc: remove UBSAN warning in dw_mci_setup_bus()
Date: Fri, 17 Jun 2016 13:07:25 +0900 [thread overview]
Message-ID: <5763777D.8040601@samsung.com> (raw)
In-Reply-To: <576352CA.3080605@samsung.com>
Hello Jaehoon,
On 2016년 06월 17일 10:30, Jaehoon Chung wrote:
> Hi Seung-Woo,
>
> On 06/10/2016 10:29 AM, Seung-Woo Kim wrote:
>> Hi Jaehoon,
>>
>> On 2016년 06월 09일 21:38, Jaehoon Chung wrote:
>>> Hi Seung-Woo,
>>>
>>> On 06/08/2016 01:07 PM, Seung-Woo Kim wrote:
>>>> This patch removes following UBSAN warnings in dw_mci_setup_bus().
>>>> The warnings are caused because of shift with more than 31 on 32
>>>> bit variable, so this patch fixes to shift only for less than 32.
>>>>
<snip.>
>>>>
>>>> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
>>>> index 2cc6123..dff045e 100644
>>>> --- a/drivers/mmc/host/dw_mmc.c
>>>> +++ b/drivers/mmc/host/dw_mmc.c
>>>> @@ -1099,7 +1099,8 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
>>>>
>>>> div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
>>>>
>>>> - if ((clock << div) != slot->__clk_old || force_clkinit)
>>>> + if (((div < 32) ? (clock << div) : 0) != slot->__clk_old ||
>>>
>>> Well, we don't expect that clock is 0.
>>> if clock is 0, it should be passed to " if (!clock)"..
>>>
>>> During initializing card, clock is 400KHz or less..I understood what you want to fix.
>>> But I taught this is not correct.
>>
>> It seems slot->__clk_old is not really clock but a kind of value to
>> store both clock and div in one variable. And at least, my compiler
>> calculates right shift with more than 32 as 0. I am not sure there is
>> other proper value for the case.
>>
>> By the way, in my test environment, clock is calculated as like
>> following steps:
>> mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 400000Hz,
>> actual 400000HZ div = 250)
>> mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 200000000Hz,
>> actual 200000000HZ div = 0)
>> mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 52000000Hz,
>> actual 50000000HZ div = 2)
>> mmc_host mmc0: Bus speed (slot 0) = 400000000Hz (slot req 52000000Hz,
>> actual 50000000HZ div = 4)
>> mmc_host mmc0: Bus speed (slot 0) = 400000000Hz (slot req 200000000Hz,
>> actual 200000000HZ div = 1)
>>
>> and only the first case is reported as the warning. If you let me know
>> any proper value, then I will fix with the value.
>
> I think that "clock << div" and__old_clock are used for checking whether clock is changed.
> So it doesn't need to rotate with div.
>
> Could you check the below codes?
>
> if ((clock != slot->clk_old) || force_clkinit)
> ...
>
> slot->__clk_old = clock;
>From the comment about alignment of slot->__clk_old, it says that "keep
the clock with reflecting clock dividor". So to me, it is better also
adding slot->__dlv with your suggestion. I will send patch like it, soon.
Regards,
- Seung-Woo Kim
>
> Best Regards,
> Jaehoon Chung
>
>>
>> Thanks,
>> - Seung-Woo Kim
>>
>>
>>>
>>>
>>>> + force_clkinit)
>>>> dev_info(&slot->mmc->class_dev,
>>>> "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
>>>> slot->id, host->bus_hz, clock,
>>>> @@ -1129,7 +1130,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
>>>> mci_send_cmd(slot, sdmmc_cmd_bits, 0);
>>>>
>>>> /* keep the clock with reflecting clock dividor */
>>>> - slot->__clk_old = clock << div;
>>>> + slot->__clk_old = (div < 32) ? (clock << div) : 0;
<snip.>
--
Seung-Woo Kim
Samsung Software R&D Center
--
next prev parent reply other threads:[~2016-06-17 4:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20160608040654epcas1p2be228e3e02e35a640cb1e65228df79ad@epcas1p2.samsung.com>
2016-06-08 4:07 ` [PATCH] mmc: dw_mmc: remove UBSAN warning in dw_mci_setup_bus() Seung-Woo Kim
2016-06-09 12:38 ` Jaehoon Chung
2016-06-10 1:29 ` Seung-Woo Kim
2016-06-17 1:30 ` Jaehoon Chung
2016-06-17 4:07 ` Seung-Woo Kim [this message]
2016-06-17 5:16 ` [PATCH v2] " Seung-Woo Kim
2016-06-20 2:34 ` Jaehoon Chung
2016-06-20 3:30 ` Seung-Woo Kim
2016-06-20 3:45 ` Seung-Woo Kim
2016-06-20 4:09 ` [PATCH v3] " Seung-Woo Kim
2016-06-22 1:27 ` Jaehoon Chung
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=5763777D.8040601@samsung.com \
--to=sw0312.kim@samsung.com \
--cc=jh80.chung@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ulf.hansson@linaro.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