From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5182BC433F5 for ; Sat, 14 May 2022 11:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbiENLLs (ORCPT ); Sat, 14 May 2022 07:11:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiENLLq (ORCPT ); Sat, 14 May 2022 07:11:46 -0400 Received: from mail.enpas.org (zhong.enpas.org [46.38.239.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 441C7167EC; Sat, 14 May 2022 04:11:44 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail.enpas.org (Postfix) with ESMTPSA id E7A8EFF959; Sat, 14 May 2022 11:11:43 +0000 (UTC) Date: Sat, 14 May 2022 13:11:40 +0200 From: Max Staudt To: Vincent Mailhol Cc: Wolfgang Grandegger , Marc Kleine-Budde , linux-can@vger.kernel.org, Greg Kroah-Hartman , Oliver Neukum , linux-kernel@vger.kernel.org Subject: Re: [PATCH v6] can, tty: can327 CAN/ldisc driver for ELM327 based OBD-II adapters Message-ID: <20220514131128.5e647fb8.max@enpas.org> In-Reply-To: References: <20220512182921.193462-1-max@enpas.org> <20220513205907.6d5473ff.max@enpas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 14 May 2022 12:14:24 +0900 Vincent Mailhol wrote: > But I still think it is possible to do pointer arithmetic. > > len = strnchr(elm->rxbuf, elm->rxfill, '\r') - elm->rxbuf; > (I let you check that I did not do an off by one mistake). > > The above should also work with memchr(). Although the C standard > doesn't allow pointer arithmetic on void *, GNU C adds an extension > for that: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html > > As I said before, your for loop is not fundamentally wrong, this is > just not my prefered approach. You have my suggestion, choose what you > prefer. Yeah, this is the arithmetic that I'd like to avoid here. In my opinion, it is clearer with indices. If I were searching through a UTF-8 string (i.e. with variable width chars), that'd be another matter entirely IMHO, and I'd rely on C library functions that know more about UTF that I do. But it's really just naked ASCII bytes this time. ...unless memchr() may be faster than the loop? Could this happen? Max