From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9AA9C4332F for ; Fri, 25 Nov 2022 15:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229706AbiKYP60 (ORCPT ); Fri, 25 Nov 2022 10:58:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbiKYP6T (ORCPT ); Fri, 25 Nov 2022 10:58:19 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76C1D4AF0B for ; Fri, 25 Nov 2022 07:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669391897; x=1700927897; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Y9bTL14X4whNb/Mndo70gBsRMAZq0yxwpnPLUHzKUYM=; b=G6XqI9b5WNIZferzvlYxRQVsUnIGXiIGqgHKC74kBNCjZDs8kc9Z50q7 bakFxgz8/87Ki+udDoODcZCKb6AJxsnr6JPl0+BQ2fMUNpALa9qb+A45j w908VHCsIte/f72UeMQbUk5NC0Cx6R9/ELLYBTk2VzzGa53hYzL7jz9AM OP52xMuxyxo9w47DmBtPWJSRDVJxVDU1QvAjuyOnnQ5jGUn80eMC1RwY9 Dqmma1olCMFUDhEoHij8HxVrWNsCE1d5EYOc6rCHYYhfbiQZHc8TMV+Rn 71Fqm/e8AFbN+GoSEFAet6gOIqCbLT355WZqpuPFH70k59yLUCq63aI6H w==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="376648768" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="376648768" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:58:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="731474894" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="731474894" Received: from smile.fi.intel.com ([10.237.72.54]) by FMSMGA003.fm.intel.com with ESMTP; 25 Nov 2022 07:58:15 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1oyb5h-00HIMQ-1g; Fri, 25 Nov 2022 17:58:13 +0200 Date: Fri, 25 Nov 2022 17:58:13 +0200 From: 'Andy Shevchenko' To: David Laight Cc: LKML , Andrew Morton , Steven Rostedt , 'Joe Perches' , Linus Torvalds Subject: Re: [PATCH 0/1] Slightly relax the type checking done by min() and max(). Message-ID: References: <7e594ad64e444d448c747688b8f28249@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7e594ad64e444d448c747688b8f28249@AcuMS.aculab.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 25, 2022 at 03:27:07PM +0000, David Laight wrote: > From: Andy Shevchenko > > Sent: 25 November 2022 15:21 > > On Fri, Nov 25, 2022 at 03:00:40PM +0000, David Laight wrote: > > > The min() and max() defines include a type check to avoid the unexpected > > > behaviour when a negative value is compared against and unsigned value. > > > However a lot of code hits this check and uses min_t() to avoid the error. > > > Many of these are just plain wrong. > > > > > > Those casting to u8 or u16 are particularly suspect, eg: > > > drivers/usb/misc/usb251xb.c:528: > > > hub->max_current_sp = min_t(u8, property_u32 / 2000, 50); > > > > I don't buy this. What's exactly wrong with this code? > > Consider what happens if propery_u32 is 512000. > The returned value is 0 not 50. I considered that and there are two things to consider on your side: 1) it's coming from device property; 2) device property is validated using YAML schema. On top of that, the wrong property is on the user. We have a lot of stuff that user may put wrongly, but it's user's choice. Any better example, please? -- With Best Regards, Andy Shevchenko