Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1064893iob; Fri, 13 May 2022 21:44:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWkJIQN6VJ0zUKSE09RiNQQpyOlZh8WpYW6oZZHquHuGHZLSDZhgAiaw7CyIsz+gQx7pgG X-Received: by 2002:a5d:4649:0:b0:20a:e17e:56de with SMTP id j9-20020a5d4649000000b0020ae17e56demr6311275wrs.450.1652503444744; Fri, 13 May 2022 21:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652503444; cv=none; d=google.com; s=arc-20160816; b=CM0y3ehCZyhGt1W3XQRD1UEKel5v1j3vtpd4FcrqWCoG+mmnpW28gkcUDSgZ7ycyzy +dznDo+27vZtM4QZLjP5qL48AWSczceQlZHf2wSojTxguNMaRcJR8vP5V2DriIMR2e8P i3zE+Hyj2xR7EEoCQ3itAuipZbnOoysBdxvHFK9B6W2fihDDY83cv7JZ4BwFTr7Ti5E6 4u2/XMGA81utcvaOUAgAFIEfmPp1kcPI0IC5ILNBQWhBFXOEmiyeGtHtFRd6QWGk6ly9 RGdVD2ko/yG3R02jEd85Kavs68HpJNHOyMl6S5tG00iZuhRxy+ddH3GcaFa3AcImD4Ql 442Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8WSBvqMryDIwNgu/wfY0/kMuB0Kk0HwqZOwbYGWHfGo=; b=z45OC8i+FVE6kzNXvXo6uUMjC1f8JEt0EVTbVxGpnQUcGemLvziiTY+JWqzuu+KDPv 46Z82lj5MCe+PGKYc2oAcEG6HTc/3bTI/0Fs4yNKd/taPpIHkv/8ZGGt657vg0z7gOcv byEti9CoFWSU3kU4bwsT5W9PzX4KlCJhjeamdF3DXXJ4y19mLSDJg7+pzwG+rIINNQOY iMqfykpX3Xt1wZJn/Q/Iz9burDDMVaoGzr8UVcmD2pD5nBiTMFvLYMJ/4q+9MUzO62sn EqmTwZ5PVhBD6rMhNiywuM7fz2r2ajnghfWyBMqFTxzw/2xvtHavOIzi0/nXO8QGpgvd DOaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YKjLuOpx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d5-20020adffd85000000b00207a8e0e5d1si4033313wrr.640.2022.05.13.21.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 21:44:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YKjLuOpx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AB839356C0C; Fri, 13 May 2022 20:14:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbiENDOj (ORCPT + 99 others); Fri, 13 May 2022 23:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231151AbiENDOh (ORCPT ); Fri, 13 May 2022 23:14:37 -0400 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 614DB3545A5; Fri, 13 May 2022 20:14:36 -0700 (PDT) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-2fb9a85a124so104116617b3.13; Fri, 13 May 2022 20:14:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8WSBvqMryDIwNgu/wfY0/kMuB0Kk0HwqZOwbYGWHfGo=; b=YKjLuOpx4hqmXTkS1EgYbu6JMMXHxd2Xe/P2hKK8yMT9mF781cJ8rkpPKmPAQQHMa7 k9kCDoODBEYRzCoPlIfJIjmaAYTVgiYUBn7Gt9ef875ai3va/8Ex9WCbdSHRNLpbi8yx 1Qlt/VuzO5EqcAtKzF0sr6HYswS2WTbO0JJUBtlCFsdIjl1gQXFxav5tuijsnmGB/uJ4 Fp8HvK/QyY0Pwwjhw0Yj0uoE9/bZBXlhxE42vDKWdsEIegT3YGXsvBJCXmBn5XZ903ly GHcl3o5I+2mnWI+bqIfsJeDB71YvSM8d80t8bUO4qR31/AJ/AI1L3tQmb6z7sogeaAdE Iu6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8WSBvqMryDIwNgu/wfY0/kMuB0Kk0HwqZOwbYGWHfGo=; b=3w3zlGI0ENnLSSRCZH74DnmX8JknVPW6VPBCh99UapF7HF5rwFQHCkxbPbS5WUinCq wOhUmvtNZdJ9TK/sUv18ICMqAhPKlIaZc/T97SRGBmmI2HuzyBf70ma5x35rn/wKvTe1 W7A9zQbefVOnFtoIv3jHBb4px2mjKyc1EB7/VH14W+sqiRvWaOvr/kva9ei1TCXWSjuI m6IAlsJlyIGmfnSdHOc7ak/TY+hR2HXLl84IMzT03BZ7acvZF9dBh3Azr9sxPx7/t1zi fHq6ui1qltdo8FybtMJ110p03O/O/CmTNwyfS0So78LGcMn9JOn+TsXhn8yLMG33Eadv Bc5w== X-Gm-Message-State: AOAM531ODVK3BT5+MH09lJbYZa7d3FcyN++x3mKjxEzMRqjGwFUFIxLz SPWNdm5KzbtNCM2MrFnzMSYb5t1MR6CIBhVv3sk= X-Received: by 2002:a81:3d43:0:b0:2f9:7d:f320 with SMTP id k64-20020a813d43000000b002f9007df320mr9319855ywa.191.1652498075592; Fri, 13 May 2022 20:14:35 -0700 (PDT) MIME-Version: 1.0 References: <20220512182921.193462-1-max@enpas.org> <20220513205907.6d5473ff.max@enpas.org> In-Reply-To: <20220513205907.6d5473ff.max@enpas.org> From: Vincent Mailhol Date: Sat, 14 May 2022 12:14:24 +0900 Message-ID: Subject: Re: [PATCH v6] can, tty: can327 CAN/ldisc driver for ELM327 based OBD-II adapters To: Max Staudt Cc: Wolfgang Grandegger , Marc Kleine-Budde , linux-can@vger.kernel.org, Greg Kroah-Hartman , Oliver Neukum , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 mai 2022 at 03:59, Max Staudt wrote: > On Fri, 13 May 2022 15:31:20 +0900 > Vincent Mailhol wrote: > > On Fri. 13 May 2022 at 11:38, Vincent Mailhol > > wrote: [...] > > > > + case ELM327_STATE_RECEIVING: > > > > + /* Find delimiting feedback lines. */ > > > > + for (len = 0; > > > > + (len < elm->rxfill) && (elm->rxbuf[len] != > > > > '\r'); > > > > + len++) { > > > > + /* empty loop */ > > > > > > Question of taste but would prefer a while look with the len++ in > > > the body (if you prefer to do as above, no need to argue, just keep > > > it like it is). > > > > Actually, what about this? > > > > len = strnchr(elm->rxbuf, elm->rxfill, '\r'); > > Actually I'd use memchr() if anything, but not really here. I do end up > using the actual index. And since both strchr() and mrmchr() return > pointers, I'd rather avoid them because I prefer to use indices > whenever possible. You are right. strnchr()'s result can not be used as is. I was a bit careless when writing my response. 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.