Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3368249pxp; Mon, 14 Mar 2022 18:00:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAUGQ1EVqZmlTy6v3mw3y+M7+GYI2v2yf/I7trvx/qVaO1OAqdpECtkyIvwbYwUUmSQmf7 X-Received: by 2002:a17:90a:4e87:b0:1bf:1d62:b710 with SMTP id o7-20020a17090a4e8700b001bf1d62b710mr1859135pjh.36.1647306043198; Mon, 14 Mar 2022 18:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647306043; cv=none; d=google.com; s=arc-20160816; b=q8T92IeXRoeJHNg/Ct7hdDYpAvmZTPBiRvW0iAeP4YD1LZyC56lnDI9N2MtC+t19AW exadh61fyVBm3foeOQLLR/PTD50JCaAg9/258tVgaHWgMtcuNnPc+pz0vIP5YnqHEPCf lVNROJPx4px0J26roJVRgN0i0ZBxdkUkux4mW9N6I/Z6dDYq+eoN37hFqPmWoHGpjQMC eY96UTT5vDeFBwM4zz3pAyz9PHyBhrD9s3RDnaJi6mbGs0qi/PajnU9q41OgNqmhEt04 XOS9DGsri+h/IqkdN65sUaXXMtBWXdR7Br193RJJvdMatH47ZEAtywvSnJ3HcrHhv6LF +Kmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=w6BUVTIBu0q8n1fRYhD8c1m/SeWeuai79PSw3ovXeA4=; b=q8DRUoytbcXPD4RNnr6pMTdhW60Jy0JxxfXhbKCv7+HoN1q29En4sKY4ZGGpdORoff c7Tl9u2bmkJHIvOjHXzdI1PtfsNchF0sQDqElgzTlKGyXghlFtiz1N5ZmdcTpC0iJDLi HRKm5IvRw9HmJNHeZfnUr7/6NkFoGCTEaa9gWktYTlEKDr4VTZePXHjQtajZa+4kWJwV 473qHXnUbKAZyyloyAutJWsthqiD8ls2fY6/0Dv/9H+xZJkTvp6f7WvbDHZXb2IJ4EAv jOLomG5W6w0pDTq0Z/1JpQ70MknidZXMg6Q56UwDALohYGqPk9/h1+pf/kH9N0FfKnT+ cOyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170903120900b0014fdff69c2bsi17605146plh.528.2022.03.14.18.00.27; Mon, 14 Mar 2022 18:00:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232728AbiCLVXA (ORCPT + 99 others); Sat, 12 Mar 2022 16:23:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229803AbiCLVW6 (ORCPT ); Sat, 12 Mar 2022 16:22:58 -0500 Received: from mail.enpas.org (zhong.enpas.org [IPv6:2a03:4000:2:537::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D8F9C184B53; Sat, 12 Mar 2022 13:21:50 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail.enpas.org (Postfix) with ESMTPSA id DEE0F101CB4; Sat, 12 Mar 2022 21:21:48 +0000 (UTC) Date: Sat, 12 Mar 2022 22:21:42 +0100 From: Max Staudt To: Vincent Mailhol , Marc Kleine-Budde Cc: Wolfgang Grandegger , linux-can@vger.kernel.org, Oliver Neukum , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: Re: [PATCH v3] can, tty: elmcan CAN/ldisc driver for ELM327 based OBD-II adapters Message-ID: <20220312222142.21591629.max@enpas.org> In-Reply-To: References: <20220307214303.1822590-1-max@enpas.org> <20220309135414.34f77251.max@enpas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vincent, (Hi Marc,) Thank you for your in-depth look at it - especially regarding stale things that reflect its age, such as cf->can_dlc vs. cf->len. This driver has been gathering some dust. I've reworked the code according to your review. @Marc - could you please have a look at this? The elmcan code currently has a dummy mailbox_read() function for rx_offload because can_rx_offload_add_fifo() requires it - is this intentional? @Vincent - two more things have remained, and I hope it's okay once I explain them: 1. _memstrcmp() - memcmp() vs. str(n)cmp() The _memstrcmp() function does not compare strings, it compares raw buffers. I am just using C strings for the fixed buffers to compare against, as that allows for shorter and easier to read code. The NUL byte at the end of those strings goes unused. Also, I have not looked at the assembly produced, since the semantics are different: str(n)cmp() needs to look for NUL bytes in the buffer(s), which is unnecessary here. As a bonus, NUL will never even occur because my code filters those bytes out upon reception from the UART (it's a documented quirk of the ELM327). Finally, even if I were to use strcmp(), the code would still look just as ugly. Except the machine would also look for NUL bytes, and the next human to read the code would wonder why I'm comparing strings and not buffers. Hence memcmp(), to help the code self-document and the compiler optimise - I hope that's okay. 2. Useless parentheses in a for loop's condition: I left those in there because it gets hard to read otherwise, IMHO. It's really a matter of taste though, and if you insist, I'll remove them. With if, it's easier to keep it readable: if (a == 1 && b == 2) { ... } Whereas with for, I've already used multiple lines to visually separate the initialiser, the condition, and the incrementer. Hence the parentheses to visually separate the two subconditions. Matter of taste really, and I'll change it if you insist. That's it! Everything else is already patched for a future v4 of the code. I'll CC you once I send that out. But I'd like to wait for Marc's feedback first. Thanks, Max