Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1147841rdb; Fri, 9 Feb 2024 11:42:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXg8QEowAu8L2x6vpqw6ghAcJHzVkdgmTkkiW/urRrea+MjgbuTxKWSPPQNs0y3Y73AFzXkbcDIOdXrikYKfx2rNhXbhU65HkNmq0bCZg== X-Google-Smtp-Source: AGHT+IG0syNkOV9WRQbu6npxj9pHrpA/Q3U7rWujBDc2Xt7ABv1GFbn1VSixV8jiPqOJ+Cge+ncM X-Received: by 2002:a05:6a21:8ccb:b0:19e:be98:fc68 with SMTP id ta11-20020a056a218ccb00b0019ebe98fc68mr89468pzb.52.1707507734553; Fri, 09 Feb 2024 11:42:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWTTJfQgIJNnehBXyiEGI0YBsbPjpMFJeUgxaHwQ5HtIR6u3JkDDHMLN47E7LfYtVfl2GMBkSpz9F9fFAsyL8WwtF8BIwwdBrY7t09MMw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id sr5-20020a17090b4e8500b00296a02062desi2206202pjb.8.2024.02.09.11.42.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 11:42:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59893-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=jIx2O0BX; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-59893-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59893-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E4E96286864 for ; Fri, 9 Feb 2024 19:40:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A4B984A45; Fri, 9 Feb 2024 19:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jIx2O0BX" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB5097F496; Fri, 9 Feb 2024 19:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707507598; cv=none; b=ERXZp+jqKoMJArZrpyX3fwPL5tRTqmg7aA3LP3+ECVewxThGI5XVNSMTXKpPlwDfgpGEzzvhsKCiblx0xeTHmk3paFJpqPYc9EkchHvvQC7KTj0yWgPGoYz/FVbJ8VNG41MSOqZyZga7SNtVrCzUDCav+EmpvZ65URjaRVO//IQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707507598; c=relaxed/simple; bh=p50ceEzr8fqyzxu4AYepp96pYziEc9mrmHTAdFEP5TY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R8z00J/wvi7qpH9CVdou6oRoVJvEzpSWsq/ztCoxqBpbH/TqDr/9vYQtyTbbLJPH0RpQyLebtIB/IN+wnMQzm4D0U475iyEePCJ5cekvJ9p8pmU4NMb4j8kl3GtwJR1E39jIs4Gg7b6Gz6tr1tjT25VRGpGC3TKq0Z8t7yOgOwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jIx2O0BX; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707507596; x=1739043596; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=p50ceEzr8fqyzxu4AYepp96pYziEc9mrmHTAdFEP5TY=; b=jIx2O0BXNkciG2GxUjN8SgYF2iMv5eaJIAXYe/t25cEIjfu1iCUXeuqB nJPrc00/BYpIG0HhMt4vOvAVTzjCvkgdtQ9wh+iYJ/7bLn5gZjPvrG4F+ qqo6d2cAjQEh9h9v/ztJ6G8yCY6tfpj/K2jrmGtaJY4barXuZUdxZgbgF 3L/Viw3MxR5MWKAX67NoWEWnJtdNrDUsw4P+UkQfq9XsvwWK6YkL5t7TA 3uSvxsuW7aFO3Logj18aJRnLTHX0GrsmT+D1vt0FMw75oCDYpDxDZBxkc FX6Z4EO8udvTo1u+HdVzUgGmTkKAzaYla2hwOqC5igs02My0PJcvmScBy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10979"; a="5341077" X-IronPort-AV: E=Sophos;i="6.05,257,1701158400"; d="scan'208";a="5341077" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2024 11:39:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10979"; a="910802533" X-IronPort-AV: E=Sophos;i="6.05,257,1701158400"; d="scan'208";a="910802533" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga002.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2024 11:39:52 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1rYWiz-00000003GSs-2G2A; Fri, 09 Feb 2024 21:39:49 +0200 Date: Fri, 9 Feb 2024 21:39:49 +0200 From: Andy Shevchenko To: Abhishek Pandit-Subedi Cc: Heikki Krogerus , linux-usb@vger.kernel.org, jthies@google.com, pmalani@chromium.org, Neil Armstrong , Dmitry Baryshkov , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Rajaram Regupathy , Saranya Gopal , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/3] usb: typec: ucsi: Limit read size on v1.2 Message-ID: References: <20240209060353.6613-1-abhishekpandit@chromium.org> <20240208220230.v4.1.Iacf5570a66b82b73ef03daa6557e2fc0db10266a@changeid> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Fri, Feb 09, 2024 at 10:01:07AM -0800, Abhishek Pandit-Subedi wrote: > On Fri, Feb 9, 2024 at 6:28 AM Andy Shevchenko > wrote: > > On Thu, Feb 08, 2024 at 10:02:38PM -0800, Abhishek Pandit-Subedi wrote: .. > > > + if (ucsi->version <= UCSI_VERSION_1_2) > > > + buf_size = min_t(size_t, 16, buf_size); > > > > Please, avoid using min_t(). Here the clamp() can be used. > I think this is likely the 4th time I've been tripped up by an > undocumented practice in this patch series. says > nothing about avoiding min_t -- why prefer clamp()? While in this case it will work correctly, the size_t is unsigned type and 16 is signed, while buf_size is unknown in this context. It means if buf_size is signed, the min_t gives wrong result. clamp() is better choice. See also, e.g., https://lore.kernel.org/all/20231004064220.31452-1-biju.das.jz@bp.renesas.com/. > Please add the > recommendation here > (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/minmax.h#n10) > and I am more than happy to change it after. It's not my recommendation :-) https://lore.kernel.org/all/CAHk-=whwEAc22wm8h9FESPB5X+P4bLDgv0erBQMa1buTNQW7tA@mail.gmail.com/ Feel free to submit a patch. .. > > Shouldn't magic number be defined? > The comment right above this line documents the number. > As this is the only use right now, I don't see a need to make it a > macro/constant yet. OK. -- With Best Regards, Andy Shevchenko