linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Robert Abel <rabel@robertabel.eu>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Willy Tarreau <w@1wt.eu>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH 3/4] auxdisplay: charlcd: fix x/y address commands
Date: Mon, 26 Feb 2018 17:57:15 +0100	[thread overview]
Message-ID: <CANiq72njsuu5PF5ML5T__1Mmcw3zeb2u7MQc5+BBj0inVaxJDw@mail.gmail.com> (raw)
In-Reply-To: <CANiq72mu2NkDx4XqXzcO39N8AZg50h+BxrONJ3eCc7LjJ0rJKg@mail.gmail.com>

On Mon, Feb 26, 2018 at 5:49 PM, Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
> On Mon, Feb 26, 2018 at 12:54 AM, Robert Abel <rabel@robertabel.eu> wrote:
>> NUL-terminate each individual number to be parsed.
>> To do this, the next command character and a pointer to its argument
>> are found and stored. The command character is then overwritten by NUL
>> before kstr* functions are called on the buffer.
>
> It would be useful to have this description in the code itself as a comment.
>
>>
>> Signed-off-by: Robert Abel <rabel@robertabel.eu>
>> ---
>>  drivers/auxdisplay/charlcd.c | 53 ++++++++++++++++++++++++++++++++++++--------
>>  1 file changed, 44 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c
>> index a3d364e6c666..24cabe88c7f0 100644
>> --- a/drivers/auxdisplay/charlcd.c
>> +++ b/drivers/auxdisplay/charlcd.c
>> @@ -471,28 +471,63 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
>>                 break;
>>         }
>>         case 'x':       /* gotoxy : LxXXX[yYYY]; */
>> -       case 'y':       /* gotoxy : LyYYY[xXXX]; */
>> +       case 'y': {     /* gotoxy : LyYYY[xXXX]; */
>> +
>
> Extra empty line.
>
>> +               char* nxt_esc;
>> +               char  nxt_cmd;
>
> I think skipping the "e" in the names do not buy us much :)
>
>> +               char  cmd;
>> +               struct charlcd_priv_addr tmp_addr;
>> +
>>                 if (!strchr(esc, ';'))
>>                         break;
>>
>> -               while (*esc) {
>> -                       if (*esc == 'x') {
>> -                               esc++;
>> -                               if (kstrtoul(esc, 10, &priv->addr.x) < 0)
>> +               /* sequence is processed whether legal or illegal */
>> +               processed = 1;
>> +
>> +               /* copy current address to temporary buffer */
>> +               tmp_addr = priv->addr;
>> +
>> +               nxt_cmd = *esc++;
>> +               nxt_esc = esc;
>> +
>> +               while ('\0' != *esc) {
>
> Please do not change the style of the code w.r.t to the rest of the
> file, which writes tests with the non-lvalue on the right-hand side
> and do not compare against '\0'. Same for the rest.
>
>> +
>
> Extra empty line.
>
>> +                       cmd = nxt_cmd;
>> +                       esc = nxt_esc;
>> +                       nxt_esc = strpbrk(esc, "xy;");
>> +                       if (NULL != nxt_esc) {
>> +                               nxt_cmd = *nxt_esc;
>> +                               /* terminate current sequence with NUL */
>> +                               *nxt_esc++ = '\0';
>> +                       }
>> +
>> +                       if ('x' == cmd) {
>> +                               if (kstrtoul(esc, 10, &tmp_addr.x) < 0)
>>                                         break;
>> -                       } else if (*esc == 'y') {
>> -                               esc++;
>> -                               if (kstrtoul(esc, 10, &priv->addr.y) < 0)
>> +                       } else if ('y' == cmd) {
>> +                               if (kstrtoul(esc, 10, &tmp_addr.y) < 0)
>>                                         break;
>>                         } else {
>> +                               /* break on unknown command or ';' */
>>                                 break;
>>                         }
>
> { } not needed (your patch doesn't touch this -- just pointing it out).

Disregard this one, just checked and coding-style.rst specifies one
must use braces if the other branches need to use them.

Cheers,
Miguel

>
>> +
>>                 }
>>
>> +               /* unknown commands in sequence will be followed by at least ';' */
>> +               if ('\0' != *esc)
>> +                       break;
>> +
>> +               /* clamp new x/y coordinates */
>> +               if (tmp_addr.x >= lcd->width)
>> +                       tmp_addr.x = lcd->width - 1;
>
> tmp_addr.x = min(tmp_addr.x, lcd->width - 1);
>
>> +               tmp_addr.y %= lcd->height;
>> +
>> +               priv->addr = tmp_addr;
>>                 charlcd_gotoxy(lcd);
>> -               processed = 1;
>>                 break;
>>         }
>> +       }
>
> On a general note, the code seems a bit convoluted for what it does,
> specially without the comment written in the commit message :-) Isn't
> it simpler to use a tiny array in the stack and put the numbers to be
> converted instead of modifying the input sequence and dancing with
> pointers?
>
> Thanks for the patch!
>
> Cheers,
> Miguel
>
>>
>>         /* TODO: This indent party here got ugly, clean it! */
>>         /* Check whether one flag was changed */
>> --
>> 2.11.0
>>

  reply	other threads:[~2018-02-26 16:57 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-09 23:50 [PATCH 0/3] auxdisplay: charlcd: miscellaneous patches Robert Abel
2018-02-09 23:50 ` [PATCH 1/3] auxdisplay: charlcd: fix hex literal ranges for graphics command Robert Abel
2018-02-09 23:50   ` [PATCH 2/3] auxdisplay: charlcd: use null character instead of zero literal to terminate strings Robert Abel
2018-02-09 23:50     ` [PATCH 3/3] auxdisplay: charlcd: replace octal literal with form-feed escape sequence Robert Abel
2018-02-10  9:43       ` Miguel Ojeda
2018-02-10  9:29     ` [PATCH 2/3] auxdisplay: charlcd: use null character instead of zero literal to terminate strings Miguel Ojeda
2018-02-10  8:58   ` [PATCH 1/3] auxdisplay: charlcd: fix hex literal ranges for graphics command Miguel Ojeda
2018-02-10  9:20     ` Willy Tarreau
2018-02-10  9:41       ` Miguel Ojeda
2018-02-12 13:56         ` Miguel Ojeda
2018-02-13 13:36         ` Andy Shevchenko
2018-02-13 19:15           ` Willy Tarreau
2018-02-14 23:17           ` Robert Abel
2018-02-15 10:57             ` Andy Shevchenko
2018-02-25 23:34               ` Robert Abel
2018-02-25 23:52                 ` Robert Abel
2018-02-25 23:54                 ` Robert Abel
2018-02-25 23:54                   ` [PATCH 1/4] auxdisplay: charlcd: fix two-line command ^[[LN not marked as processed Robert Abel
2018-02-25 23:54                     ` [PATCH 2/4] auxdisplay: charlcd: name x/y address struct Robert Abel
2018-02-25 23:54                       ` [PATCH 3/4] auxdisplay: charlcd: fix x/y address commands Robert Abel
2018-02-25 23:54                         ` [PATCH 4/4] auxdisplay: charlcd: make home command unshift display Robert Abel
2018-02-26 17:16                           ` Miguel Ojeda
2018-02-26  8:46                         ` [PATCH 3/4] auxdisplay: charlcd: fix x/y address commands Geert Uytterhoeven
2018-02-26 22:29                           ` Robert Abel
2018-02-26 11:44                         ` Andy Shevchenko
2018-02-26 16:54                           ` Miguel Ojeda
2018-02-26 17:09                             ` Andy Shevchenko
2018-02-26 17:26                               ` Miguel Ojeda
2018-02-26 17:56                                 ` Andy Shevchenko
2018-02-26 23:00                                 ` Robert Abel
2018-02-26 22:38                           ` Robert Abel
2018-02-26 23:06                             ` Miguel Ojeda
2018-02-26 16:49                         ` Miguel Ojeda
2018-02-26 16:57                           ` Miguel Ojeda [this message]
2018-02-26 22:43                           ` Robert Abel
2018-02-27  5:19                             ` Willy Tarreau
2018-02-27 19:31                               ` Miguel Ojeda
2018-02-27 23:29                               ` Robert Abel
2018-02-28  0:05                                 ` [PATCH RFC 0/2] auxdisplay: charlcd: fix movement and home commands Robert Abel
2018-02-28  0:05                                   ` [PATCH 1/2] auxdisplay: charlcd: fix x/y address commands Robert Abel
2018-02-28  0:05                                     ` [PATCH 2/2] auxdisplay: charlcd: make home command unshift display Robert Abel
2018-02-28  4:21                                 ` [PATCH 3/4] auxdisplay: charlcd: fix x/y address commands Willy Tarreau
2018-02-26 23:05                           ` Robert Abel
2018-02-27  5:20                             ` Willy Tarreau
2018-02-26  8:35                       ` [PATCH 2/4] auxdisplay: charlcd: name x/y address struct Geert Uytterhoeven
2018-02-26 15:59                       ` Miguel Ojeda
2018-02-26  8:34                     ` [PATCH 1/4] auxdisplay: charlcd: fix two-line command ^[[LN not marked as processed Geert Uytterhoeven
2018-02-26 15:53                       ` Miguel Ojeda
2018-02-26 23:08                   ` [PATCH 1/3] auxdisplay: charlcd: fix hex literal ranges for graphics command Robert Abel
2018-02-10 18:31     ` Geert Uytterhoeven
2018-02-10 18:58       ` Willy Tarreau

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=CANiq72njsuu5PF5ML5T__1Mmcw3zeb2u7MQc5+BBj0inVaxJDw@mail.gmail.com \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rabel@robertabel.eu \
    --cc=w@1wt.eu \
    /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;
as well as URLs for NNTP newsgroup(s).