From patchwork Wed Dec 13 13:22:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 177986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7770161dys; Wed, 13 Dec 2023 05:23:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwv4yBMn2lrx4I+11UpVmTs9rc6apymj9tJ5eHxojyR3TEeySJHVzExkDfQ1b+QvS0O59e X-Received: by 2002:a17:90b:1d88:b0:286:b8a5:c29b with SMTP id pf8-20020a17090b1d8800b00286b8a5c29bmr6265026pjb.32.1702473788840; Wed, 13 Dec 2023 05:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473788; cv=none; d=google.com; s=arc-20160816; b=lSpG0X99aTAfAAL6VehppRTXs5XUnD9twGYBB+TtqjaF/uFsfdwd9c0dq9Ih8Sel1Y FIEUcMsmDS7cvLp9khB9TRFRoL6QF6UC5jcfvzEI1T/R7I5OVE4lEhygtLa07g2TYdSK J3n9b157DS4cr3CehcZ60afS4hJrjuBPDvnLY18bSyIGOULIG04fnKnPOsYLMf/rLwxl kLQQ2KPxyIPOk+8RA9vkBvA8YSjrlbUiB8jcYy6YskkigJwOtT4ZEtlaVz9JAwF4rRSb GmPheB4WEIp5ifd3+UF3R3JzVhBySi7C5JwghOtRhgKvYkjuNPw7lIFEobQKd31Wtlv/ xOdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=jY13RsvR2p7nAVWn/STfQAiQyGaFoi3utwqqvjImNyk=; fh=ZbCQPu0FctmlODUV4hl0D3nNviDtCWsXxDm5W5r7MJY=; b=ApthCoDUU08Gb2czwp7zzkNpnx7p//bk17hIYrCHEPo2tYPbZelbgG008JX/ElnRii BScVRYSbKyukz+bjLYmNtMSkeNdPoBJ8EP/a5nakUCJ4We4mTt6h3pg1C6X+66h93ALJ WJQlX9VkVIA8prN8+sU9VMpOY+KM48YMVHlBPQWJY9YW6XGADtjhHUS6rXD03OxrnI+J bAXc8rj4eXX4zkNXUX3tVDUq/PuXjbMyhUqa+D/6xpNDiv8ikj1QS9JTJeTloOzqR8q3 ImfmelF6fq8m8uZ7BWLsuBMV3fTPkY5sDXKeC89aqP0x4NB4pfIYT4qff6NnW7fDrgOz +sww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Oq6YiaXY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id gl13-20020a17090b120d00b002868ad0a84bsi10981815pjb.37.2023.12.13.05.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:23:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Oq6YiaXY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D055B8221134; Wed, 13 Dec 2023 05:23:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378917AbjLMNWr (ORCPT + 99 others); Wed, 13 Dec 2023 08:22:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjLMNWq (ORCPT ); Wed, 13 Dec 2023 08:22:46 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE983FE for ; Wed, 13 Dec 2023 05:22:48 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40c4846847eso31659355e9.1 for ; Wed, 13 Dec 2023 05:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702473767; x=1703078567; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=jY13RsvR2p7nAVWn/STfQAiQyGaFoi3utwqqvjImNyk=; b=Oq6YiaXYzOaamZEp7gALMU85D8UlkkbjER2evO96CvFXabDs7pnBOtC4HMvZK7JnKp Ok4KU4DDUffyyGaRepYKa+gAz8W0F4WJAuH5EGKxhgFrQKKi1a3CjqENOjAAf1+J7XlP MvnQG6FQgwwTXU/+YPaOVI78XfrMcmsAP5WI4WkIE5yhIa0udduEEikW7NiflFe8+sGi 3h5JsJApeit2VNth/gMlSUQXyuT6Q5+ugNXZe1AagCvnTFVlRC0jyCLwf/NhtqHrvcoe qvUdPOesNmJlCjBn834dDD7vnjp+MIWYUJ3Aa5wAepn6lMVfy/ei2rnx2jks92FzHxXh h7iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702473767; x=1703078567; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jY13RsvR2p7nAVWn/STfQAiQyGaFoi3utwqqvjImNyk=; b=BnttK0SXJJ2sFRveRs9NpegQNHfMhHTDfG/cxl28mMbcuXJDV1PTvHj/4Gx/a3+Hqn 8YVSGssFI+KleJ2aYMp4tSF1MesBzPEoa4lwBPjEyEr3gSgnCYl5iB2syMk8ITNBRHMz QaK0gh+VdhM7A78gN3aPY6Fw40Dnw4A2fUBJ9Qr7otEg/VcUm0UVHREzOes0E9xB/k4V 7LNTahWwQQi22PtT64YRN5KOYuIqzuzd5IOrUYDJpAX+23kebu7KQV0uRGtRfTs/o01B vlF0sPzG696NnnZX+kTpKdXbj2tu1Ag9XIWAHCR80I8ap8Y2j/cbVBBqdz1TsjnvEO/O DO4w== X-Gm-Message-State: AOJu0Yxpj1JovamxNa9PPBMazXnovAlr+e4koccYYoNUzWYhOSFPWvwy Sja6SYz6x1ERe4ynHbHvXveLLw== X-Received: by 2002:a05:600c:3556:b0:40b:4c54:3d78 with SMTP id i22-20020a05600c355600b0040b4c543d78mr3882194wmq.28.1702473767093; Wed, 13 Dec 2023 05:22:47 -0800 (PST) Received: from localhost ([102.140.209.237]) by smtp.gmail.com with ESMTPSA id s5-20020a05600c384500b0040b632f31d2sm20693616wmr.5.2023.12.13.05.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:22:46 -0800 (PST) Date: Wed, 13 Dec 2023 16:22:43 +0300 From: Dan Carpenter To: Linus Walleij , Lee Jones Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH v2] usb: fotg210-hcd: delete an incorrect bounds test Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 05:23:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785173155631350109 X-GMAIL-MSGID: 1785173155631350109 Here "temp" is the number of characters that we have written and "size" is the size of the buffer. The intent was clearly to say that if we have written to the end of the buffer then stop. However, for that to work the comparison should have been done on the original "size" value instead of the "size -= temp" value. Not only will that not trigger when we want to, but there is a small chance that it will trigger incorrectly before we want it to and we break from the loop slightly earlier than intended. This code was recently changed from using snprintf() to scnprintf(). With snprintf() we likely would have continued looping and passed a negative size parameter to snprintf(). This would have triggered an annoying WARN(). Now that we have converted to scnprintf() "size" will never drop below 1 and there is no real need for this test. We could change the condition to "if (temp <= 1) goto done;" but just deleting the test is cleanest. Fixes: 7d50195f6c50 ("usb: host: Faraday fotg210-hcd driver") Signed-off-by: Dan Carpenter Reviewed-by: Linus Walleij Reviewed-by: Lee Jones --- v2: Use the correct Fixes tag. Add Reviewed-by tags. drivers/usb/fotg210/fotg210-hcd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/usb/fotg210/fotg210-hcd.c b/drivers/usb/fotg210/fotg210-hcd.c index b2f8b53cc8ef..8c5aaf860635 100644 --- a/drivers/usb/fotg210/fotg210-hcd.c +++ b/drivers/usb/fotg210/fotg210-hcd.c @@ -426,8 +426,6 @@ static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh, td->urb); size -= temp; next += temp; - if (temp == size) - goto done; } temp = scnprintf(next, size, "\n"); @@ -435,7 +433,6 @@ static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh, size -= temp; next += temp; -done: *sizep = size; *nextp = next; }