Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7830354rwd; Tue, 20 Jun 2023 06:52:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7NU8GxNJ8aa9uX2mzs+UWo7kwtGlL7dx+jwqDcSceOeLGM2iAtx3sUiBGAeS+tuGyoxXvj X-Received: by 2002:a05:6a20:4314:b0:117:3c00:77da with SMTP id h20-20020a056a20431400b001173c0077damr12765181pzk.20.1687269135167; Tue, 20 Jun 2023 06:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687269135; cv=none; d=google.com; s=arc-20160816; b=YDs0CJZQLKfPG7bDM3WJL/n6FyYRvlh8OXF+Q84smyKlMc1tEWpTSX3C56Dev8f65X cZwYasxSNoB+KbNWbTjftnurGdKMMCGRSqOujjQwkW5pkGaOZ3tHEFMzmS6WeK6av/RA 7kxl3rgke5dpyR1fVUj7uu5aZEviG+CwWqYLMEaIGDDFdlWQOSxvydPUr3CkddQcAlLj KkAHWfKtmzqbBPSwkFX0Sm7772A4qMfHpXBRqd2oNsOe3WnnDsjNjjae2P6EtLtNGFVA FwgoXcgP13zPFD9TdYa9NiLE0lesdYU2KNatbvfvgUMudZjMU+w/hj0yNszoKTQE4q97 qQOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=4djnHc/93xx80cvO3bAeuwhwj2lz0FlqxFt1tzTrZ04=; b=so/dgC3OutMTcozlgpo0PMjrTDryhA2swrz6zQwIuAUoACDk0lPFdUMMrqM2aTP9VL 9OkV3t7CQ457lnCgkRxUVY0HrmNq9vG4m0t7LGuJ46a6SxKcuXzE91sfwBY4r4ylFqIU D6FcqovLAwAF3FOI6+PURpYg5/X1X1UpNgDzwqkWiM6puJkYbbvXUcvhbRxsjs6JfehH RaIugP+an8QNzsCGSNIXNJr3n5S6h15uXUEixqRFcIGYoPIVlyTh9kAhq6gVmxBQa1Ui MlcTJdZxc61/J4v45muWN1eSykF4AwBjKzMIokFk1YCvxahuqdZTdVPL2Er/QHHbFyDG MDTw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o1-20020a170902bcc100b001b55070e154si1877830pls.96.2023.06.20.06.52.00; Tue, 20 Jun 2023 06:52:15 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232989AbjFTNfU convert rfc822-to-8bit (ORCPT + 99 others); Tue, 20 Jun 2023 09:35:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232938AbjFTNfS (ORCPT ); Tue, 20 Jun 2023 09:35:18 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DECC71AC for ; Tue, 20 Jun 2023 06:35:16 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-308-di_iNizVO7mVDItkyCs4jg-1; Tue, 20 Jun 2023 14:35:13 +0100 X-MC-Unique: di_iNizVO7mVDItkyCs4jg-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 20 Jun 2023 14:35:11 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Tue, 20 Jun 2023 14:35:11 +0100 From: David Laight To: 'Andy Shevchenko' CC: Jens Axboe , Greg Kroah-Hartman , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v1 1/1] pktcdvd: Use clamp_val() instead of min()+max() Thread-Topic: [PATCH v1 1/1] pktcdvd: Use clamp_val() instead of min()+max() Thread-Index: AQHZoF6FIyAIB0qgg0eyK+mA2nZIdK+TnYVAgAAGJgCAABE0AA== Date: Tue, 20 Jun 2023 13:35:11 +0000 Message-ID: References: <20230616142614.36206-1-andriy.shevchenko@linux.intel.com> <9258be5d31104805b63bb1a64317a448@AcuMS.aculab.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 From: 'Andy Shevchenko' > Sent: 20 June 2023 14:25 > > On Tue, Jun 20, 2023 at 12:06:49PM +0000, David Laight wrote: > > ... > > > > + *hi = clamp_val(*hi, 500, 1000000); > > > > (standard rant about minmax.h) > > > > clamp_val() is pretty much broken by design. > > It MIGHT be ok here but it casts both limits to the > > type of the value being compared. > > In general that is just plain wrong. > > > > Like min_t() it is generally ok because the kernel only uses > > unsigned values between 0 and MAXINT. > > > > If min/max were ok, then using clamp() should also be ok. > > Submit a patch to fix it, if you think you can make it better. > Obviously your comment can be addressed separately if we even > need that. Did you try using clamp() ? To see why clamp_val() is broken consider? unsigned char val = 200; ... xxx = clamp_val(val, 10, 300); This sets xxx to 44 - not exactly expected. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)