Received: by 10.223.185.116 with SMTP id b49csp3964092wrg; Mon, 26 Feb 2018 08:57:08 -0800 (PST) X-Google-Smtp-Source: AH8x225/QMA7THus8TLAmzfeC8jYteVaGXSPwpjcvQ7tfe1pwvWQqaZDun7MVZGVSu5kzdRDtQVI X-Received: by 2002:a17:902:5609:: with SMTP id h9-v6mr11137253pli.302.1519664228795; Mon, 26 Feb 2018 08:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519664228; cv=none; d=google.com; s=arc-20160816; b=kIkEbXAVW5cpzWCV7B2qw4CO68VG7Ht95ZhGgrRbNNwFkOw1Uh8Rg1EDaQcexggfw0 F+yA9dKJv5m9yOYWTJQ4jRXPe/UuoBNU1R6eTGwyi8vZ9pQ64aq2hk1zHw1KS9Bjteo1 GUziKOFs2iZV5gIrJ5kvq2a3LgQII+2Zxg60kh1cyRgyvfschxzrbaUADcsuYLHaW4CI FY5Zs5mVmEKULDKnjPg0GID/kqJYOZ+QWf4NamWZ2v7AzEOexQpTGI6cvPYXaiyoxvP/ UANJoK9a2pHfnyDBQ5LimGRV5q+SMxCG+TlV73UziNvQdr7T5p/BHZtR8KZlaWswRbNO A2zQ== 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=kiftLe9S1+1kNWxVWgIAAs7VXjjjq2ItsA+SONBYLSQ=; b=0TqoQtr6NHbLKBr4XnzqH0XkhKxoHN8rOdQQCrTSq/ARxudFRbFYKrehJaKs1BK8zV VYAQn3S0u3WB2MS0ry6jkzYwTUBcgFGw6u3dpYlLlcsWAPYCMyxPNd7LWKlFVT78LVPr gllIiNlLRqd5vFoCPo90ZxMDS+bwp5rhISZzJxdbsfOr9Y4haIaJH+ibqyFO0gXp4Kez JMtQbFdY3N3SnXhssp+9hNttUrqEwRyD+nEe6IEy+6KdE3vdLk/7aO4eQPPMk7Y9YobS zaa3a+pOG3DF05WgtfBM53hwaeq1Rq5qqC/FncuCbZP5gFgYWpQ188RvQU28rRx8gH2G kIPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pzJ1owdd; 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.56.53; Mon, 26 Feb 2018 08:57:08 -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=pzJ1owdd; 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 S1751550AbeBZQzW (ORCPT + 99 others); Mon, 26 Feb 2018 11:55:22 -0500 Received: from mail-qk0-f174.google.com ([209.85.220.174]:41434 "EHLO mail-qk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750941AbeBZQzU (ORCPT ); Mon, 26 Feb 2018 11:55:20 -0500 Received: by mail-qk0-f174.google.com with SMTP id w142so8045983qkb.8 for ; Mon, 26 Feb 2018 08:55:20 -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=kiftLe9S1+1kNWxVWgIAAs7VXjjjq2ItsA+SONBYLSQ=; b=pzJ1owddrzrXMdfVY3WEE1ZlhenrDMK1OSx8k/J+I60dG0BAnt4pqCl16oY+YZTG71 Avb4Q08Vn56oWB9pcm3+7Zbs5o73bbLzOf4rN9CMphWsQ3bUTdmoepqb2+dwg5LbO5yw Bfqg0Gh0G8YGCDFx08TPGYOAC1jkhJbwK3bHyA9c6Ky8OW1Ve9wMhjDgkFNPPlp4AsBW hTwp1QwUu6OUGCk4S1oIQeTz7D55X6zbClxwQnCfqM16xtfVmoSNkkSZxFtCcmqf2ta0 4djvgAyGHNohVLlGd+Qrl5KNacIDqJa8itrNXWy+fkecm+BA2e0cUwtnBjY9rIe3x0er ZnXg== 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=kiftLe9S1+1kNWxVWgIAAs7VXjjjq2ItsA+SONBYLSQ=; b=s44i+UrtwHDZvvniOPpJy53c2xOxXVMlojV+GtgPMaLPdeZ/VkmuoludyFOIMTKN9S u77cDbgg3JlOMY9LJMagumehNKEBh+eSrxIOiBQ/y1CDY57sgZwebK2cMASKVDJRyrJG Oe5MJRnV5w3huobfW1yUP5zmC8Ym5qpUitvwWHbMPPIWeEQ26vQZluFoAu0701SsewYz UCm0KKNDbQf11LqDml2om8sFrCrWvgAdJLl19Zxl2G8MWlKo0HCUWH3hffHfbXsILDpW HKS2B7vEshbH09VlRc+2xoQ9q3ksMyic4AaxhF20gKdROD3lXatMceB89uwsb2YcJrsa qWPg== X-Gm-Message-State: APf1xPCMfWdUNcYzQ7zNO/UZ7q1ojqVLLEgqdHvbOJ4P6NoqwpLJJIQF 5rxyPDMa+9DmqjVWDD9tqVAO12WPUSuaUsTb9pfnBWrm X-Received: by 10.55.88.7 with SMTP id m7mr18453090qkb.133.1519664120164; Mon, 26 Feb 2018 08:55:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.52.247 with HTTP; Mon, 26 Feb 2018 08:54:59 -0800 (PST) In-Reply-To: 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:54:59 +0100 Message-ID: Subject: Re: [PATCH 3/4] auxdisplay: charlcd: fix x/y address commands To: Andy Shevchenko Cc: Robert Abel , linux-kernel , Willy Tarreau , Geert Uytterhoeven 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:44 PM, Andy Shevchenko wrote: > On Mon, Feb 26, 2018 at 1: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. > > Can we avoid yoda style of programming? > >> case 'x': /* gotoxy : LxXXX[yYYY]; */ >> + case 'y': { /* gotoxy : LyYYY[xXXX]; */ >> + >> + char* nxt_esc; >> + char nxt_cmd; >> + char cmd; >> + struct charlcd_priv_addr tmp_addr; >> + >> if (!strchr(esc, ';')) >> break; >> >> + /* 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) { >> + >> + 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 ('y' == cmd) { >> + if (kstrtoul(esc, 10, &tmp_addr.y) < 0) >> break; > > Perhaps instead of dancing around kstrtox() better to switch to > simple_strtoul() ? It seems deprecated: /* Obsolete, do not use. Use kstrto instead */ extern unsigned long simple_strtoul(const char *,char **,unsigned int); > >> } else { >> + /* break on unknown command or ';' */ >> break; >> } >> + >> } >> >> + /* 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.y %= lcd->height; >> + >> + priv->addr = tmp_addr; >> charlcd_gotoxy(lcd); >> break; > >> } >> + } > > Same indentation level or my mailer hides this from me? It is the same, but it is also how the other 'case's do it -- which in this case looks just wrong since it is the last one of the switch. I am not sure what is the preferred way of doing these kind of blocks, coding-style.rst does not seem to give an example for this case. Cheers, Miguel > > -- > With Best Regards, > Andy Shevchenko