Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1655068iob; Sat, 14 May 2022 16:08:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhwk3J1WMlrdw7lrcSiSBLx0nMbhRVDHBIPm6HUXN6hCmZxKRGCfBO4sgNE+IUXClxkhww X-Received: by 2002:a5d:47cc:0:b0:20c:6b7c:8a19 with SMTP id o12-20020a5d47cc000000b0020c6b7c8a19mr8496881wrc.608.1652569688927; Sat, 14 May 2022 16:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652569688; cv=none; d=google.com; s=arc-20160816; b=cpZLwrpnohNzaGfoGXw1y1flzRCCXXnkfe43NfOGrpbSuoO0cOOY1id7IoroonDJKb oZ9nLeYbr5bC6WTlspYXyfM7u6GO9MGnaaLXmb1je+DpNw7eIJCuaeQawwXHQLD2Ld/c S6upZ5a6zd4jghzILBEZQhocpsUZRPHNHt7MjHBqbZRZbr48/XQE48AVN7NJe8Lmwa+0 XO6LTUVauLJSWxy2HqLESlBMu90LLD+JY3Y0TsfN0byBtS/qjL8v3O3/XR7fk5H7xZZq nc6+36g3cFbZatYJKGvWI5yWaOGg3GmW8QkxPvw/z2V7Q1Zj0jhua3QpVwt6sXFKGl/A NyCQ== 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=Weh5jjHCbopmn32ZCDDAN7bFPf92kl9sSSkrlWRTIbA=; b=db52Sg89Bn3CjSsPZaxThIRHO9UQAwSIeUe9hn0mYZRRYr/+pl/iVPpKFVsxO3PPjF YYzFjFFaqnvqtcxeQ15GTdUVcwayfeeGDI7N/honhGglpi6Pahf+gryfEUGg4VIu3xa/ 9YlRBxfPhb2INYP0fsR0vQ1NmnmsH/AiWXQCNkrTxbzNh/ruzac8G3uiV0YxncxpdQ7M CnfRZZKD+dBuAbg5MEEd7XXytnvZKmrOYTphIhdJ7RZFwEzUeiyrbZyp/Y2guu1bHxxu aShl/skY9tucwHdVAXaWM8q9V0s//AeAQhTEpWGwp8sQV3RAeKsYBEcBKdnUqTybdP4e x/Tw== 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 v3-20020a05600c428300b00394351ae8b3si8204524wmc.207.2022.05.14.16.07.43; Sat, 14 May 2022 16:08:08 -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 S230013AbiENLLs (ORCPT + 99 others); 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 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 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