From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 601E12D7DF6 for ; Sat, 31 Jan 2026 22:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769900326; cv=none; b=UX7SVPX447uP0vBVkATNaJvHgPqum6Ri6jfY4wUJwMJoARE33rUQIQym5rUeZEvXHtF1ymP0pxC9uo61ND3ndwfFE4S8blYmKUBSHJFPGH0Xnit5dI7GobcI0VolHwtaISL7WmDMoknFj5yXTU+Hy8nuaAOPGuap2c0Mqcv8oco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769900326; c=relaxed/simple; bh=qvLXj3C0ln4Ro9ot8vq6rkQafH04GAkmaEXUNJbE/e4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hdH9xv742qst+lw40tp+aE0UaNYntgw+KIBfmIBCay3vYSoaz3falEUuKvP9p33XmX9flR0OSH+tCUMFj6rjCiD+Z1RHX0OFOF/wBFU2Shim45UuT165vjEFI4BCKsJIe3zcmw5+GrtfZ2abHUeG5/AD4LE4K/n2NomV43N4kGQ= 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=EW/ZM7LN; arc=none smtp.client-ip=209.85.128.50 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="EW/ZM7LN" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-47ee0291921so29898545e9.3 for ; Sat, 31 Jan 2026 14:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769900324; x=1770505124; 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=aNAeH9OugmIY6Mp3nXkb+OeX3PyAHH7b09rhZzLav6E=; b=EW/ZM7LNqlfy4yB/tYA2Q2vJmUDdLpcuJVzcUal0Khbnps1cImrIzXY9Vw3+3aAhRK Gs+bk6DiUUjUeXNl/muSndt0Bn4dtygL4LEFyzIPGYrpOjRF3H4nHdHCeg6YQi00RRm4 HzHaBJsjIgeL/pgSB0aTXFnhnCsPjbPw4TUhRUjUc6UsJ7SQXPfVhYUMTFgMl/BQOgAE GxKFdJf2Z1NHggLF3y5tfnwDk2D9NSplgfXel7kHFlLSRj4573Wg2yi5+AbHlTFcziOI L/oQHz09CdLS0/kl2mc4U4pjIFbJnx/o27eXKMpotVPRwPP3FDNW5Kreh6wC3FKT1Rrz v4XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769900324; x=1770505124; 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=aNAeH9OugmIY6Mp3nXkb+OeX3PyAHH7b09rhZzLav6E=; b=Wmk9Ggw48peGI5DF+au6QDJBa/jyZRXqw/iJ2E3RK+lcgbO8URwRYNXzheQaMfqKip 97hoWpfHuEHNDiDmcNtuKLpI8c2OflJbMDfRe/UDmmizn4LH82w48K0UPx6LnImSdIOj /h7ufz/PyLizH+o8tRxgkIeheun2zP5nmIUHclIBrOwHXijP57+cWgM2PVRGW1Gu09Ro JxNdkmQOaHi4wVo9JMYu/2CqDXLvtQsjDEHV6XT3McXX90e/LhThngwTAhND0of9kPxr bKqFt2lJ8FnWhmLHaDpCUpyQdUSHxvWGP+9NRaq+33dBaFzBaQvgPaWOIZNjnSIiubl/ XtDg== X-Forwarded-Encrypted: i=1; AJvYcCXwnA9XNTYvxfg33uL2yJ8dFqmmVXMtacWYJZ7kQZlU6N9tN4vEvi1LPdZjXLyMztx6sqBj/72FZu7lDBc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/mAcGVUVnxOXdHxliAYY0xLvGi16DOF2Oh9NrV8sAHlbAteSJ W+s2xXNxo8uE7e76eV8snjVrOR7hG6z7/OXmn/9Onbb+Qc4M4ZXCILTj X-Gm-Gg: AZuq6aL1hkPGZ7JeZGpxxa5iPXdlxhawRINxR/sYSOuPCFn9gtJLPvF3ZAPznvWcGg4 ZH/doh90kVT30Apeh7R+Mtpl1u1DP0c1YlKxV7ImN2WxLBvviAMwy4b9opE7dKMxnRtBFgIv5Dq EvSWpeaOBsGbF3d86SmwhBBm9QjKh/X0VczFOjthRfMSeEbPfMR15HZrBpSakw7yFg2g0wls1/F 7aYn9Huq61l4rCeKmkQN3PdFMSN2IfZYn8jhJ5yR8NFOh5F34ESYxzkIQw2wIJN8wXTabufNPgI l9Of7De/DlZKaMmVSyIJlHFe3QBnZf8fm2JQOt4q7nMfDyZ2oYsZuJMjM7OXBeqVFlvkoMCb/AW FTRM+gWbYZgzQcHeH6/SOd0GjDATeB5IjXnCJbQjfVcVaZWkpOJ12UWWoLsNZCMi3gi9mZHaPNs 9Rl2rB6r+ttoDeM8x0sHPC6v7ayBEffqyk1PAzqXPcy7oIIWex1rkq X-Received: by 2002:a05:600c:4fc7:b0:480:68ed:1e73 with SMTP id 5b1f17b1804b1-482db4f39fcmr85146115e9.36.1769900323417; Sat, 31 Jan 2026 14:58:43 -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 ffacd0b85a97d-435e10ee057sm35694247f8f.15.2026.01.31.14.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jan 2026 14:58:43 -0800 (PST) Date: Sat, 31 Jan 2026 22:58:41 +0000 From: David Laight To: William Hansen-Baird Cc: Dan Carpenter , gregkh@linuxfoundation.org, straube.linux@gmail.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] staging: rtl8723bs: replace ternary comparison with min_t() Message-ID: <20260131225841.6ec19c9d@pumpkin> In-Reply-To: References: <20260131133146.8174-1-william.hansen.baird@gmail.com> <20260131155525.05e1645e@pumpkin> 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 Sat, 31 Jan 2026 16:43:54 -0500 William Hansen-Baird wrote: > On Sat, Jan 31, 2026 at 08:35:55PM +0300, Dan Carpenter wrote: > > On Sat, Jan 31, 2026 at 03:55:25PM +0000, David Laight wrote: > > > > > @@ -1024,7 +1025,7 @@ static unsigned short rtw_parse_assoc_security_ies(struct adapter *padapter, > > > > > pstat->flags |= WLAN_STA_WPS; > > > > > copy_len = 0; > > > > > } else { > > > > > - copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2); > > > > > + copy_len = min_t(int, sizeof(pstat->wpa_ie), wpa_ie_len + 2); > > > > > > > > Use umin(). "int" is wrong because we don't want negative values > > > > stored in copy_len. > > > > > > And the correct way to fix min() bleating is to change the type of the variables. > > > Using min_t() ought to be frowned up and only used as a last resort. > > > > > > In this case I think all the variables declared with wpa_ie_len can/should be > > > unsigned int. > > > > > > > That also works. > > > Hi Dan and David, > > Thanks for your help. After reviewing the code, I do see a few checks > ensuring wpa_ie_len is never negative. > Therefore umin() is safe in this case, and for v3 I'll update the patch accordingly. umin() is a bit better than min_t(). A subtle change is doing 'wpa_ie_len + 2u'. > Would you prefer I leave it at that, or is a broader change to > make wpa_ie_len unsigned worth doing in a separate patch? I scanned the code some of the variables seem to be different signedness in different functions. But a 'false error' from min() is really an indication you should be looking at changing the types of the variables themselves. My main thought looking at that code is that functions are far too long and have far too many local variables. You also pretty much don't want to use u8/u16 for locals just because the values are small, it doesn't (really) save space and can increase code size. David > > Thanks, > William