From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 58714372AA2 for ; Thu, 20 Nov 2025 09:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763630289; cv=none; b=pCe+2HKsQkkErn3F3Wecs9JgF78Pc9BIAKTFOhzOfLuA5sBpcL4mkB8+o7iLOHnZTsrBf4rroSjgXw5iTxSDhN8LxuoGOSepEoZpPpOsJzDsGjsZZJF6mh+0fQ12bVFJ9cKUNmK4wqU4OjQBCMLtpIDdsEwhntLzJp/zwtUn/vo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763630289; c=relaxed/simple; bh=cOCZIxwjKMi3bYiXetHKPNouQTg+nLQHAL2FKWDV1+w=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tCJ2nmes9qhQ9jle1pjNRWzgyhX28jF4yizfe7ZAwft+9Xr9hvy1EJGi5o8IGsKMXbQDF+Qiw6YTXwXAt595a2fuW/yEcjdUBX8gp8ye8pWoO398/z42UMbcWSRLBh4ZC0tWA6hJpO9RA9kX1aVf7GF3JgDkRH4NzUhSYrXvays= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FxzByf2d; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FxzByf2d" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-477b198f4bcso4578945e9.3 for ; Thu, 20 Nov 2025 01:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763630284; x=1764235084; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=7/8wHSFGo4XpBnjotrRiitIWkuRDZTnNB1ymCbgQE6s=; b=FxzByf2drzUM0Z8/WLsg9656XRcRESaveQeUN0OT6kY/6IIIwb2riLRED2CzfYWAof DSLxAdHFCsf45Iurp3zKsuHW4lG3AdTmfpApOiofJroZBfjvvg+/jbzF/ONetEG6h1tN i5jcqoSHf9XqWOF9YQ8EORy0DBk9+f/2niJjw1gliTuXWb64TBXpTg2+UC3kq3SK+Fr5 M38yYss5FDx1L64aJRrNKJbiCVgOpf4FkQF4Zzq4oa0mcW09badmEIxwoM9aGtDDEXy5 oTkx+Ad9UPp/mpgsihbsvtBRPuigIsZ2p2DIe7o3lziV7bhN0D5InbM0DCb0vdywpnGs v0IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763630284; x=1764235084; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7/8wHSFGo4XpBnjotrRiitIWkuRDZTnNB1ymCbgQE6s=; b=hNYEo/nRyfwgUJ+7rUtofih38mlaSiK/j8NijiXjk+aCI2fOCVDDFfPC4YNVdj9zoG MZZW568yGJBi45Mkv0qnHv2oFzz7yWMo13sitfFdRwVchk7EM+47LiCOyqThKP76Npfq GnFMMLT1xZX8r1gp30s0GvRy0b9qS10PV9+vUH/1x2Di0Qg1RKUYnX1+kuTJMrICHYcL uABnij5yzVdDEVLJvUDR6o6hfDK44ZABHWZIF4cN5EQQx0VoskfpFiuDWI+v9Dmxetf+ CHI68/4rl1/zYfl3lNKTp0WxrtQ1dploM0dq1zIGZogK8hP8uIs6kadowetnve/hN5wq mzVw== X-Gm-Message-State: AOJu0Yyq/6HfVzoi4B5NIglz4ZChg0O5jAPcGU1TES9Ksqat+5pPsA8E JvpEIk2pQYMrTtCwJriFH+hLIROHkivo+KT511UGlTp/5KFRK1vEu7uq X-Gm-Gg: ASbGncvtJZYmxpr+iq+7bU9igHaJDEBI2kYiiuhwX5/kTTIDLUmSIcc7A9yqtUZCR4n A7wPHqyrmBbFZoASkePTF76ssyBHnZ23Azkme7Us/t5pddO51/W0As8ZGmhbfw9qS21lq9h4+ma RAVxeZn+q98q9kWkCAozlJlgOUoQ4+UUCtZzQ0DyZvkBSBm5PbZTGor/NnSvpAColeioroU+lpJ PuMGtb544c+7ejIx5JmS6Pmhdp+JxtUifp5eCFs+SsC+fBhDznqcCOdw6weLtYp0jq5EeTSbIP7 S0reaczQlc54k9LtWVtmx7nhnoBbw9mzc20MgmgmtAxXzdeWOGb0hvAr78vYfXA4sDV/rGUaZeu ehY+4F9cB5wCZy9ZwHUuH1dqX3Si1TYoxhxh4QZYQXBLSuxUgJJiTx61v3JKPJWzZf2uPXsc8/a NtiYi6nvj+8aOW7/LoTXx3wgii8/zFcatsI5R4RtQ1a6G1ivt3+Xj9 X-Google-Smtp-Source: AGHT+IFB4woOW3FzxtKhlFfktUD86/qnlFtEe68TjnX8yUVs4orgmTuNUXZKUmsoHXgKwc2KIfzPnA== X-Received: by 2002:a05:600c:450a:b0:471:672:3486 with SMTP id 5b1f17b1804b1-477b9dfa9d9mr17462695e9.15.1763630284235; Thu, 20 Nov 2025 01:18:04 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477a973390csm59748875e9.4.2025.11.20.01.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 01:18:03 -0800 (PST) Date: Thu, 20 Nov 2025 09:18:02 +0000 From: David Laight To: Alan Stern Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, Greg Kroah-Hartman Subject: Re: [PATCH 28/44] drivers/usb/storage: use min() instead of min_t() Message-ID: <20251120091802.0b238c96@pumpkin> In-Reply-To: <4208129f-a768-44e2-843f-309c50ea362f@rowland.harvard.edu> References: <20251119224140.8616-1-david.laight.linux@gmail.com> <20251119224140.8616-29-david.laight.linux@gmail.com> <4208129f-a768-44e2-843f-309c50ea362f@rowland.harvard.edu> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 19 Nov 2025 21:59:42 -0500 Alan Stern wrote: > On Wed, Nov 19, 2025 at 10:41:24PM +0000, david.laight.linux@gmail.com wrote: > > From: David Laight > > > > min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'. > > Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long' > > and so cannot discard significant bits. > > > > In this case the 'unsigned long' value is small enough that the result > > is ok. > > > > Detected by an extra check added to min_t(). > > In fact, min_t(T, a, b) cannot go wrong as long as all the types are > unsigned and at least one of a, b has type T or smaller. That is backwards, both a and b have to have types at least as large as T (or rather values that will fit in T). - which is exactly what people keep getting wrong. Consider: u32 a = 4; u64 b = 0x100000001ull; then: min_t(u32, a, b) has value 1 not 4. David > Of course, in > this situation there's no reason not to simply use min(). (And if both > a and b have types larger than T, why would someone use min_t() like > this in the first place?) > > Regardless, the patch is fine with me. > > Acked-by: Alan Stern > > Alan Stern > > > Signed-off-by: David Laight > > --- > > drivers/usb/storage/protocol.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c > > index 9033e505db7f..0cff54ad90fa 100644 > > --- a/drivers/usb/storage/protocol.c > > +++ b/drivers/usb/storage/protocol.c > > @@ -139,8 +139,7 @@ unsigned int usb_stor_access_xfer_buf(unsigned char *buffer, > > return cnt; > > > > while (sg_miter_next(&miter) && cnt < buflen) { > > - unsigned int len = min_t(unsigned int, miter.length, > > - buflen - cnt); > > + unsigned int len = min(miter.length, buflen - cnt); > > > > if (dir == FROM_XFER_BUF) > > memcpy(buffer + cnt, miter.addr, len); > > -- > > 2.39.5 > >