Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1113854rdb; Fri, 9 Feb 2024 10:36:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj/bbwh/vFmuuTzU4+gKJXxqmgar/qJUWjJgOHSgq+VMjuVe9weBUvsZXeATIgCxpe3fjJ X-Received: by 2002:a17:90a:1082:b0:293:eaec:fd67 with SMTP id c2-20020a17090a108200b00293eaecfd67mr2173205pja.14.1707503794870; Fri, 09 Feb 2024 10:36:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707503794; cv=pass; d=google.com; s=arc-20160816; b=MZY6F6byPLWLh8ODrfaHsqqHTlTuZ1iHFpGlFM0NMaTHhkh7A+1yI+6kEA6iLeipty tUo81kMQ4YUUWCHhf2nBV1cDNIQJM50ARajDGbTD2ghbLmOROikFMk2nQ+iHxlNf11iv xJACJmVTZ9TLnoutM/Rii+roNdjI76UrAmnHZ7WtuZyViSPWfEpYejupFGw+6dp8H8+2 N8kCRWom3fla6gMOS9hGNVn3/Lldr78tNZBP11qJsQOZROdJmf7yaryWdK1J9DWZFkge mJFWP8mKsaeTHm0mI/SXCC2SNxR886Z9N41SO05s6PvwyyfdkWrdHMBq+Cf4BItHA6B3 cZiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=DxAXd9578hDdusxvxqROEMfzhHSW5iLGGo5hRVlkaFc=; fh=sD6aXJIOSIxQ0kValww6hM8beZehtdV9QDcssUelCEw=; b=lJAHgFwxdELwTlPpODTyI3OEWd1PLrezWlDGzpj3FWzyPCZHfMCtjs1D1/ocL6+V+y tsNrAg/tVXrs8XKdQ/fiDdT2EYeFTzeKVQgr4OSE2MYBWyW+tm1RlFnRkZp/UXNjFE5L FA18BEWJz//f0MYO/2bdmkFNDiDdlyOIpEo05r4MUUOQYUNN85qPMdajRNA0E0+iHDcR bPItcyhKg/oQXFs4TcBd8jwzR9ej2DEvo97BpxNreLU1HGGxlMiwtyuaRmJ/KTZDS45v zfpRtoZ6iG9culUk1uimBqSmXbLUVrLA+k7wCw2e7Oy5tVGhDJ89Kbrr8P5sqQm2Ctc2 C4ww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iJiRiBSR; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-59758-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCWXgNJWfrcdHREwBv5fz84qyIFd4KwS68xlGaaAudeybA7570I/qbfG+Dld/XXCwJ9x3Ha3Lk8lvrUo8gPWsBx9Mv1EU7kLhlrvgboqbg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bv17-20020a17090af19100b002970e6df4fdsi1011557pjb.33.2024.02.09.10.36.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 10:36:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59758-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iJiRiBSR; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-59758-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E67E3B26F8C for ; Fri, 9 Feb 2024 18:02:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A3D980BE9; Fri, 9 Feb 2024 18:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="iJiRiBSR" Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8D357BAF3 for ; Fri, 9 Feb 2024 18:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501682; cv=none; b=tiAjzNktHq0PxrTuNm+kt09gbXi/RRPoX7Gdst6WN/e04ybc1Mjm5X2m9E+waT5de7O3AgJvXCVEUB7YwQQ7B3Gg5cLonCWnzbjU4YkGL8o4ODwrGFZ3MsVmDusGMT1ZYgqOfFZhm/Bd68ADQpTV44L154XmBTaAEeSOZ6q9oWQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501682; c=relaxed/simple; bh=tWnDDTX6hjvn4zZMWScUR1a3jczggxxhhlZFG78n9SA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EcYugDox1vvpmAChy5Xl+aJSHV1yjoUiwdzEc0c0sUeJUKuIdiKBet2s2JT/p9TlGds1qW6+KeM1C0WpUP18LncfKuXN3XZ2PRCaSMYUQ12s23hGIBcAyuqf9l01iIey2/R/2XKfLFZQ6XNnmD+LnUyuINdIp5RrWFoRa+CUrr0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=iJiRiBSR; arc=none smtp.client-ip=209.85.219.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-dc74e33fe1bso1234148276.0 for ; Fri, 09 Feb 2024 10:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707501679; x=1708106479; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DxAXd9578hDdusxvxqROEMfzhHSW5iLGGo5hRVlkaFc=; b=iJiRiBSRIncIsn3DVJ3tybiJ+sQA+7Bo4C9dA7k4FZy+QZLxXnRINZ/f9SR1DWhd5/ NHDhBlALK6qguizN8lwDn9SMBRvnD5mq+WraiRliah9nM31AXpcgM0vC5Zk4va+xuIZV S5XZgZwsgRrJM+NDv86NLYComeWGhcp3nRE5o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707501679; x=1708106479; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DxAXd9578hDdusxvxqROEMfzhHSW5iLGGo5hRVlkaFc=; b=sLtPI0cAv8k8Bkzss2FMn/gxXPyi/YDjZW9NlFihUPqnS7yvRQ+mU0sArFdqCw+jwi 2iEkbuZjNjip+pgXE4FjFqVXoRYwjX1MX1n7Y/hqNvnDT996bHvhwP1dAfqO8OhgPJHT oG8OQdIKOGnMhYpenPYqUHiar/zIZTOQDge1SbU8uu6t11KCXYc+olfXBaTzvLJbZ4mb V5u1dHrw7ZfXFuJswvxd9yEmMmAHjtiFmCh/aMwpuw/jT6CC3BIScss4KRoqcZlfkkuZ g1VEiZexbrEC51zbWYmrzj/CDiIMRXPERehXwLkr3aoEhbz9hmnfxC6E5wtEHjCltAx7 F0Sg== X-Gm-Message-State: AOJu0YxMx5ZhYBSUg0jF3tfpzzbsmhoORAUe0tGwAHrj27MHJtg9KN37 uaXy1l4SgE70QFGTl9CY6tnRonYk3Bh10tNZMPrZP25Gm0bEZBqfxO44qIzYhEN8szoI43fvXUD seqTIh5Zms7oYeVzZiRD87oTJhByuJ5eAVMye X-Received: by 2002:a25:9cc8:0:b0:dc6:19ea:9204 with SMTP id z8-20020a259cc8000000b00dc619ea9204mr1878634ybo.61.1707501678528; Fri, 09 Feb 2024 10:01:18 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240209060353.6613-1-abhishekpandit@chromium.org> <20240208220230.v4.1.Iacf5570a66b82b73ef03daa6557e2fc0db10266a@changeid> In-Reply-To: From: Abhishek Pandit-Subedi Date: Fri, 9 Feb 2024 10:01:07 -0800 Message-ID: Subject: Re: [PATCH v4 1/3] usb: typec: ucsi: Limit read size on v1.2 To: Andy Shevchenko 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 9, 2024 at 6:28=E2=80=AFAM Andy Shevchenko wrote: > > On Thu, Feb 08, 2024 at 10:02:38PM -0800, Abhishek Pandit-Subedi wrote: > > Between UCSI 1.2 and UCSI 2.0, the size of the MESSAGE_IN region was > > increased from 16 to 256. In order to avoid overflowing reads for older > > systems, add a mechanism to use the read UCSI version to truncate read > > sizes on UCSI v1.2. > > ... > > > + if (ucsi->version <=3D UCSI_VERSION_1_2) > > + buf_size =3D 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()? Please add the recommendation here (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/in= clude/linux/minmax.h#n10) and I am more than happy to change it after. > 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. > > -- > With Best Regards, > Andy Shevchenko > > Cheers, Abhishek