Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7958298rwd; Tue, 20 Jun 2023 08:21:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7JiLIhXWEVvLvLjfNjxmThh65IDZaLFAI2Y5w4cO0ir/bcAVsao6x3xGn5IwP7cGUgLlqU X-Received: by 2002:a05:6a20:144f:b0:117:6b17:104b with SMTP id a15-20020a056a20144f00b001176b17104bmr10139458pzi.20.1687274471773; Tue, 20 Jun 2023 08:21:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687274471; cv=none; d=google.com; s=arc-20160816; b=aoVWZRy3g+V1w27Hbia91Ygaa/KM6Wb3D5EP/lz9nsfUIgMT8Yoku+sUvcqPcKjVxn qlPb9i7jixxI+ATsWrarI20x1Ap9obt+QlbKbqRQ6tqlaiZfWmuXrJXINU1VL9GUgyj7 6lplpDuyT+B2A1xKQquzyuSYEOYcqGiNnG8zNTXHjtx7sFsUdoN5I2ejlJGAQ23+pSN8 h2f3gbOC64b+Sf1Ykpto8d4QHWB0jyIHl3SkJFyfg9oEM0hL9VLNoBxth8stFLbxC4kc POgXpRxGi0ZhyooFy+eFk1HjnTbt/Ho2xILgr6u/9KP9fRwT2z5Pa5vz3PY0O9b4L+/l nX5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=JmsS0Yi7Eqf6TVpHRnA9uTsuN0MzzIRRZ15l7hBx0oA=; b=EShBC/B9IjXhGeQjj7cLqnvcUjcilwONbtgL5G5Qo5FxvMQMp4XfhdIfG2AbCd7fD7 R9tXehAs39xndp9MMEv/SZghvTaUO53/hvvtoa2DucWBiGub3i4ySn3+XB75/yGt/OvY G0r5GK+hEMiomXZBVwOsphztIGe0+Xze1om57hDlRlM8piSZtbxf0jUkVtLbjJ2Ritkn c9q+ehZfmwku4WvNxG/kHk2dLP9iGIuBwFCwHNxnW7LUBWeBvdppmiv22NmM7bc7nF+1 Xw/GL8wnfl7k+5S5SJscTu0Vd17ejU6O/ZebLEHJ48PZuuFt9BlVlgPZnTlJeYSfkJhy aXBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ls+OE77f; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a170903120b00b001b3cd4f3126si2337199plh.439.2023.06.20.08.20.56; Tue, 20 Jun 2023 08:21:11 -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=@intel.com header.s=Intel header.b=Ls+OE77f; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233035AbjFTPFY (ORCPT + 99 others); Tue, 20 Jun 2023 11:05:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233506AbjFTPEh (ORCPT ); Tue, 20 Jun 2023 11:04:37 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A7731BF1; Tue, 20 Jun 2023 08:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687273444; x=1718809444; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ivrsLAv5ei2pZb4Fe2LCuh5oh+6GLbCVwN4d6QsS9D8=; b=Ls+OE77fthsZ7s/JXh7RdhQD3L6XDslz042uflQhqPqtvD021cTH2Z3H BCVUet9v/HzWkHj2+g4W23VDSrch38e8iVY+kLSK7RmdwXLdb/yM8U6DF 9KbozY016ZC1OwFEn9d3HWD0F8PVjjUZYRVjldX7TL6lSJP5aSJ9yppu2 p/hqFtajuzq898WvqJ13+fDWJNaLc/bhGb3HYv0pJtkhXqMnlrvbqz+Nl Yta5ATv7vUDj48Uc0tlJRe4KT3e0Shp6zvI0K3uh2FhWNbMBsl1sVmEVs nvSlsYYh3wRCqZOjpa4Na1yRYyYfDdtwBrJOJCrPSe43/G0KO/bvrQrqV Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="423546437" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="423546437" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 08:03:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="708309489" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="708309489" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga007.jf.intel.com with ESMTP; 20 Jun 2023 08:03:19 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qBct4-005Had-02; Tue, 20 Jun 2023 18:03:18 +0300 Date: Tue, 20 Jun 2023 18:03:17 +0300 From: 'Andy Shevchenko' To: David Laight 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() Message-ID: References: <20230616142614.36206-1-andriy.shevchenko@linux.intel.com> <9258be5d31104805b63bb1a64317a448@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Tue, Jun 20, 2023 at 01:35:11PM +0000, David Laight wrote: > 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. Right, clamp_val() has to be improved. However this is not the case in this driver. I have just sent a v2 with clamp(). -- With Best Regards, Andy Shevchenko