From: Jonathan Cameron <jic23@kernel.org>
To: Chenyuan Yang <chenyuan0y@gmail.com>
Cc: Matti Vaittinen <mazziesaccount@gmail.com>,
lars@metafoo.de, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: Fix the sorting functionality in iio_gts_build_avail_time_table
Date: Sat, 16 Mar 2024 13:40:35 +0000 [thread overview]
Message-ID: <20240316134035.5eb47a69@jic23-huawei> (raw)
In-Reply-To: <ZfS0Rhk5WTJbwXU/@cy-server>
On Fri, 15 Mar 2024 15:49:10 -0500
Chenyuan Yang <chenyuan0y@gmail.com> wrote:
> Hi Matti,
>
> Thanks for your reply!
>
> > I think the suggested-by tag is a bit of an overkill :) I don't feel
> > like taking the credit - you spotted the problem and fixed it!
>
> You did help me figure out the real issue here and how to fix it :)
>
> > Do you think you could fix the removal of the duplicates too?
>
> Sure, I can help to implement the deduplication logic.
> Here is a potential patch for it based on your help.
> Besides, I changed the stop condition in the inner loop to `j < idx`
> since the current last index should be `idx - 1`.
Matti, I didn't follow why duplicates are a problem?
Sure the code is less efficient, but do we end up with a wrong
answer as a result (I've not checked logic, but I'd expect either
first or last of repeating values to be used depending on the alg).
I'm not convinced adding to complexity of the code is worthwhile if
its not a functional problem. I would expect a unit test to verify
that duplicates aren't a problem though (given you have unit tests!)
Jonathan
> ---
> diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c
> index 7653261d2dc2..32f0635ffc18 100644
> --- a/drivers/iio/industrialio-gts-helper.c
> +++ b/drivers/iio/industrialio-gts-helper.c
> @@ -375,17 +375,20 @@ static int iio_gts_build_avail_time_table(struct iio_gts *gts)
> for (i = gts->num_itime - 1; i >= 0; i--) {
> int new = gts->itime_table[i].time_us;
>
> - if (times[idx] < new) {
> + if (idx == 0 || times[idx - 1] < new) {
> times[idx++] = new;
> continue;
> }
>
> - for (j = 0; j <= idx; j++) {
> + for (j = 0; j < idx; j++) {
> + if (times[j] == new)
> + break;
> if (times[j] > new) {
> memmove(×[j + 1], ×[j],
> (idx - j) * sizeof(int));
> times[j] = new;
> idx++;
> + break;
> }
> }
> }
>
next prev parent reply other threads:[~2024-03-16 13:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 15:57 [PATCH] iio: Fix the sorting functionality in iio_gts_build_avail_time_table Chenyuan Yang
2024-03-14 15:36 ` Jonathan Cameron
2024-03-14 17:05 ` Matti Vaittinen
2024-03-15 7:55 ` Matti Vaittinen
2024-03-15 20:49 ` Chenyuan Yang
2024-03-16 13:40 ` Jonathan Cameron [this message]
2024-03-20 7:02 ` Matti Vaittinen
2024-03-23 18:13 ` Jonathan Cameron
2024-04-11 12:19 ` Matti Vaittinen
2024-04-26 5:52 ` Matti Vaittinen
2024-04-28 16:57 ` Jonathan Cameron
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=20240316134035.5eb47a69@jic23-huawei \
--to=jic23@kernel.org \
--cc=chenyuan0y@gmail.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=mazziesaccount@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox