Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp586886imw; Thu, 14 Jul 2022 07:11:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uboqAv9W1PUDfcgpP+CQwQ6qEoTiS1tnY320SQR1ZWXm3jz7XCrSpBMSq1gCamWYdZPBrS X-Received: by 2002:a9d:630f:0:b0:618:da60:4c62 with SMTP id q15-20020a9d630f000000b00618da604c62mr3376075otk.296.1657807908394; Thu, 14 Jul 2022 07:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807908; cv=none; d=google.com; s=arc-20160816; b=HkIheWWsM3yuYLqSvIZJ7ABs8Ic1e5I0qpI3pDaovTRcueTw5Eg8Xt+VqEzT7C3MPn r6d/35+HYCehl3SUsnGkM8iM6FJJYhsq4uyqM7GIsxMWSgQ1oY7ZOsN1JOYa3CNoJ0QM 0PckfuZP2FuZBMDnyIxaluJL2D166F1NqnValsVbmibHRCrsqzf3M7xqzaNbjA9OZJOo bri8PzNngxMrjUA6rr1altMbXcoK9Co0IECKa7u3ZloruJ04m/+Mw9DqSzrkx1a2UrtZ HOz9mBqa5X3Fa2ad3Txl1r1F8aUeKNd62+0qylViQfovEHdM72In3ia6siDLVlNNr4cL QmzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature:dkim-filter; bh=6nEqc/8db9cnSBDSgS+CSBHWXQlL3UmK0hfgzuNWVgI=; b=aedSxQxiPpj2Zowujk+12WyRAIZ//luPobiPYrkPU4YuBkFpwy0Fw5JUjEFuTcNyEP Mp7ik2NyeHCe8HynVmRpCKt84subuQicHClG/Hlw4+MLdjzL7WsVeAgdpvodwZEEcEQw 6RScDruFhq/v1mVfO1HaHDc1O5P6mmRb2PR7v/oZ+H6OWoYa4KevLdsZGtVcKBXqgHjk NzYyveJpzDy1TmOSIYjhPWxTTPa6fbuuBd4iNZ9XRpbSZHnwRnVckH9prW+S+bD/H5HQ thSpblR7BtGYJosPl2S5Q571mpw0YyshAL3u9ld6E37GmLL8FSkZJorb9YHkz38l1GPt eJ9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=mSlq5osw; 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 m20-20020a056870031400b0010c289aafc1si1500846oaf.120.2022.07.14.07.11.28; Thu, 14 Jul 2022 07:11:48 -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; dkim=pass header.i=@lwn.net header.s=20201203 header.b=mSlq5osw; 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 S239772AbiGNNju (ORCPT + 99 others); Thu, 14 Jul 2022 09:39:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232196AbiGNNjs (ORCPT ); Thu, 14 Jul 2022 09:39:48 -0400 Received: from ms.lwn.net (ms.lwn.net [IPv6:2600:3c01:e000:3a1::42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A757060510; Thu, 14 Jul 2022 06:39:47 -0700 (PDT) Received: from localhost (unknown [IPv6:2601:281:8300:73::5f6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ms.lwn.net (Postfix) with ESMTPSA id 3DAE92DC; Thu, 14 Jul 2022 13:39:47 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 ms.lwn.net 3DAE92DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lwn.net; s=20201203; t=1657805987; bh=6nEqc/8db9cnSBDSgS+CSBHWXQlL3UmK0hfgzuNWVgI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=mSlq5oswWR02kCA7qjoLfvi5QhFce7TkiQZrNRaXKqoxtxPzCa9UHBBSPUEI+CPK4 BhpnLayiPVb3bpxFQdLwohdDzwoPABmO/mtlZiLt4Jxy2CeMqJT4k3mcRCQfi20zey NMj+sIh20fb4bzPApaSE/hfEPlpiFUMnvGTKNQXEIYNfyFJjKmeHGwKO89WH/tDRRo u3RrEU5FqG8x4HT9LuAdWZiW36nMl1yL7G66EbU/224SWffUVrDnIiOyEsu+DIkKCF xs1i0ErZKraw2HUMkMh/IHqL5pfZbYtW/Uu8Di7Aj4VWTPJyvtGpXnXINHSRT0eD7r 3bDG1nJsojDGg== From: Jonathan Corbet To: Jiangshan Yi <13667453960@163.com> Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jiangshan Yi , Andrew Morton Subject: Re: [PATCH] lib/lzo/lzo1x_compress.c: replace ternary operator with min() and min_t() In-Reply-To: <20220714015441.1313036-1-13667453960@163.com> References: <20220714015441.1313036-1-13667453960@163.com> Date: Thu, 14 Jul 2022 07:39:46 -0600 Message-ID: <87bktr24pp.fsf@meer.lwn.net> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Jiangshan Yi <13667453960@163.com> writes: > From: Jiangshan Yi > > Fix the following coccicheck warning: > > lib/lzo/lzo1x_compress.c:54: WARNING opportunity for min(). > lib/lzo/lzo1x_compress.c:329: WARNING opportunity for min(). > > min() and min_t() macro is defined in include/linux/minmax.h. It avoids > multiple evaluations of the arguments when non-constant and performs > strict type-checking. > > Signed-off-by: Jiangshan Yi > --- > lib/lzo/lzo1x_compress.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/lib/lzo/lzo1x_compress.c b/lib/lzo/lzo1x_compress.c > index 76758e9296ba..9d31e7126606 100644 > --- a/lib/lzo/lzo1x_compress.c > +++ b/lib/lzo/lzo1x_compress.c > @@ -50,9 +50,7 @@ lzo1x_1_do_compress(const unsigned char *in, size_t in_len, > > if (dv == 0 && bitstream_version) { > const unsigned char *ir = ip + 4; > - const unsigned char *limit = ip_end > - < (ip + MAX_ZERO_RUN_LENGTH + 1) > - ? ip_end : ip + MAX_ZERO_RUN_LENGTH + 1; > + const unsigned char *limit = min(ip_end, ip + MAX_ZERO_RUN_LENGTH + 1); > #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && \ > defined(LZO_FAST_64BIT_MEMORY_ACCESS) > u64 dv64; > @@ -326,7 +324,7 @@ static int lzogeneric1x_1_compress(const unsigned char *in, size_t in_len, > data_start = op; > > while (l > 20) { > - size_t ll = l <= (m4_max_offset + 1) ? l : (m4_max_offset + 1); > + size_t ll = min_t(size_t, l, m4_max_offset + 1); > uintptr_t ll_end = (uintptr_t) ip + ll; > if ((ll_end + ((t + ll) >> 5)) <= ll_end) > break; So these look like good changes to me, but I am not the maintainer of this code. Maybe Andrew (copied) would have a spot for this patch? Thanks, jon