Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3742914imm; Mon, 6 Aug 2018 09:49:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcvFyG1mCVsop/bOm3zFaz5UECC0XMc6CxYhxcXaEECKuvDBTC54a61Aj/0BWbRxtHkK8B/ X-Received: by 2002:a62:2119:: with SMTP id h25-v6mr17645083pfh.112.1533574171931; Mon, 06 Aug 2018 09:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533574171; cv=none; d=google.com; s=arc-20160816; b=xqTnqcP9lM4dTCw0McsPDSep213UQKsy9w1xvvBvAZr12YP3b4g753yk4WXUAjud6Z Q9q/JH00OUW0SW0rZz8xbakjGbRdbWr02oM7nXaQWBqx+ffYb4fuSW/tjse9niTqfNL3 s/wa/YYq9wvfbRu+MTM+M2nIAo/F1HCAmnxCI/NsbQNonv0ARfwDbcSVjQ95iB5RPwb8 kZCjwW9o1SPrq1VvLzrVrCNELnsgVEBVNxNV24jc6y1sxFQoHelZoblzBRI0bUPiDAi1 1FNpOaXTyzPokmQwayYY4a22S3BtYXP81QaA7n72Y3+PpYQLn9RGwM1ZLDY3X1wUGBU0 fjrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wILEfLnz56nW/Fhy8bgHV2phcXU5uF30GSiWBo2MoYs=; b=SW9Xq6dpMtqC+aGxU1u2myKjafAQRmR8jDubj56A1ksDFXyvonDukXZJQ8DHPSOb6y LoOwFmbphpjFSvJIcGN0Gey87RF65gOO0xA4tcvfAflM03YjRra0aYC1rr88+8nCIrLw qF/tANieffXT5wljV5tkOQcz7TtJu+uJEIRqkJqML2FGx0n33kGNvyjCY8T8oB/DSiVc KC+c0EBlCUeDeHtmeQYsSCnbKvAq7OaRIZoC7905EvGaDAXqZlR5AUEpTAclUX1x6m9m A5WEVGb07Ev0JmxPNZ+aUE2A3FJsqead7AlFLj+dASIEv0XATWzhTQnObY1SuzkP/6kZ dyCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1-v6si13163649pgh.160.2018.08.06.09.49.16; Mon, 06 Aug 2018 09:49:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732033AbeHFSx4 (ORCPT + 99 others); Mon, 6 Aug 2018 14:53:56 -0400 Received: from bran.ispras.ru ([83.149.199.196]:31803 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727561AbeHFSxz (ORCPT ); Mon, 6 Aug 2018 14:53:55 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id 29092203C7; Mon, 6 Aug 2018 19:43:58 +0300 (MSK) From: Anton Vasilyev To: Greg Kroah-Hartman Cc: Anton Vasilyev , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] serial: mxs-auart: Fix potential infinite loop Date: Mon, 6 Aug 2018 19:43:46 +0300 Message-Id: <20180806164346.9986-1-vasilyev@ispras.ru> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the error path of mxs_auart_request_gpio_irq() is performed backward iterating with index i of enum type. Underline enum type may be unsigned char. In this case check (--i >= 0) will be always true and error handling goes into infinite loop. The patch changes type of index variable to int. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev --- drivers/tty/serial/mxs-auart.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 76aa289652f7..89b34bb09cde 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -1617,7 +1617,7 @@ static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s) static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s) { int *irq = s->gpio_irq; - enum mctrl_gpio_idx i; + int i; int err = 0; for (i = 0; (i < UART_GPIO_MAX) && !err; i++) { @@ -1634,8 +1634,9 @@ static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s) /* * If something went wrong, rollback. + * Be careful: i may be unsigned. */ - while (err && (--i >= 0)) + while (err && (i-- > 0)) if (irq[i] >= 0) free_irq(irq[i], s); -- 2.18.0