Received: by 10.223.185.116 with SMTP id b49csp3959503wrg; Mon, 26 Feb 2018 08:52:02 -0800 (PST) X-Google-Smtp-Source: AH8x225FZP5NxPijKlfXFEfDhmJyaVsRzyQsVgizparh1CkbCqsW0C6CmQr6VZgsl7WouvEFiKm9 X-Received: by 2002:a17:902:3a1:: with SMTP id d30-v6mr11001306pld.409.1519663922478; Mon, 26 Feb 2018 08:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519663922; cv=none; d=google.com; s=arc-20160816; b=C3uCFAlL1v/PWhmgQEtVSWFCbDvj0vkIKhzDM/bDrLPnZcrP3CHvGDs0LT8QXLfMTK XhTUGztkaNIUjAXQTnwPK6fU2XsVSsh7U1rcpHvd74XIgT0UxdHJhGhF9l7vjvVuOOaD ZDOykHJQC1DAqKKJSZtVcUdm2dhl5uMMPvtRSKXbId2OBZzdsTtQlngjonH+nbIcfqIo /VGQ/2SMXwg4FkLafsVj3nKRTs51SD3ter10bOD/v/msZY4902e6IplI19hIVLIPUmK8 FeMH/P5CeAnEpGF5Uu0GtH7NLw9Qr1dP660Fo1iCwR+jrnbGd+UUwesY1k79lB9Xrn5D 1QJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=NhPP0Y5ck3yc6WHHcQbAV53CZAcVHzPIDc9xtmE4LMI=; b=FRO+Z24NrBeLWXj4tCaobcXTjO0+NTS8cWR09Enojk+qevNt9jG6QuXMFhcs7G4CO/ 118kYre2p83dVDMovqWYRKCwfz16kkRcQs6/0K9F63zBmZ5v4Izt0JCSyoXpNdIZ9vwW Nl+QBhmj3lH4jkXhuvsY6W1ESGX3kls1QuPvhH3DP7TFhp/8UIeECHR7UgmnNqxgOWeU mb+t5rsusejG7aiAiWBm8iYKnva4eCc2waDR0pYzZ1umE3DdiK7RSrmk6+IwiTM9veOp Yttj3ZGC0C7Qc5TlIwNkbTT2GuLcnbuL6mKA5TP6AvkMVAXbFe7j7kS0Y4RyHg1SBzhq /PVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YtyBHo0C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9-v6si5847453pll.680.2018.02.26.08.51.47; Mon, 26 Feb 2018 08:52:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YtyBHo0C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751319AbeBZQto (ORCPT + 99 others); Mon, 26 Feb 2018 11:49:44 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:46514 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750986AbeBZQtn (ORCPT ); Mon, 26 Feb 2018 11:49:43 -0500 Received: by mail-qt0-f196.google.com with SMTP id m13so14815192qtg.13 for ; Mon, 26 Feb 2018 08:49:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NhPP0Y5ck3yc6WHHcQbAV53CZAcVHzPIDc9xtmE4LMI=; b=YtyBHo0ChqdTxQNW0AY7YDLDYbgaLGtnUENALmxv9eTu9vpDIq3An0F0cZ4HHcCfxr uguYR1WIm5XFXWP8Am++GCEVyG1Ckpa45rsef4W7Lgjg/1WYQouvzle7jdKqmdMnB0GG AQaBC7FYF0uh5SX3yfCJJZ4lI4HQkyPyJ/aea+YgZMmoWoLLORSGiCC/zAlGTuAZvhs8 DrW5GPnsuvcPdzeZn9s3aE/Yu+nnyPGpAP5kFMqymUWP5mVl32lj2QfaE8vFyMaAnzNp oB7crJSH4tVadEgsCis6KhgbdAzrGJ2k+9PHtlip7Ilvphz2s1fVMJlr9W7PlXxJNY5v 871Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NhPP0Y5ck3yc6WHHcQbAV53CZAcVHzPIDc9xtmE4LMI=; b=UzdpnDkAAxVwN2b2bw0ECR91DvLDHccxLlpT7TR8I+sFFq84nkKhNOIBJ71iRmhqyZ ZljY66s1BRtKBulqh5FF2mJYIbfriVx/fbYNWrFkRD440jv0RPDP6OuiIIgHV3rrZ9Rg 18FBD0CyVc3QYJ9MwrZ5N5i480RjTI6KfKkXZvLJJEDVZ/aW+AaTi/B7oUNjwI04l3xC l/bWQGBaRjznOd2KZSYq0hni/+vZLisxAUmIUh9OK7GaHGqqVRTZ8+K94DstisWtZe5S VOuOygbdLKRLcYT6uYTHeqn4zEamT5otksv7UN5YH0O7Oq/HG1Ewfa9kaUH9fdB9SvA7 yBkw== X-Gm-Message-State: APf1xPAD/D5ajiH7Fj01xgtU8v3vh3J8I03gKVo+jXCGoY0WX1E47IeN n+t9kjZ0H40Ji2cuJfNWW8Z5EkktVbnjBsNZt+U= X-Received: by 10.200.112.91 with SMTP id y27mr12398727qtm.295.1519663783050; Mon, 26 Feb 2018 08:49:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.52.247 with HTTP; Mon, 26 Feb 2018 08:49:22 -0800 (PST) In-Reply-To: <20180225235432.31209-4-rabel@robertabel.eu> References: <9ec3c54c-f8fe-22d7-783e-8cf9862405bb@robertabel.eu> <20180225235432.31209-1-rabel@robertabel.eu> <20180225235432.31209-2-rabel@robertabel.eu> <20180225235432.31209-3-rabel@robertabel.eu> <20180225235432.31209-4-rabel@robertabel.eu> From: Miguel Ojeda Date: Mon, 26 Feb 2018 17:49:22 +0100 Message-ID: Subject: Re: [PATCH 3/4] auxdisplay: charlcd: fix x/y address commands To: Robert Abel Cc: linux-kernel , Willy Tarreau , Geert Uytterhoeven , Andy Shevchenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 26, 2018 at 12:54 AM, Robert Abel 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 > --- > 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). > + > } > > + /* 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 >