Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4575984imm; Tue, 7 Aug 2018 04:03:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdxYHUIEO++TyNIrlKAhBqlZpE1NaFpKBI90dGXoASiYPcrDTgfvausuzrYED5T1Bg7uJEc X-Received: by 2002:a17:902:a9:: with SMTP id a38-v6mr17695323pla.102.1533639788515; Tue, 07 Aug 2018 04:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533639788; cv=none; d=google.com; s=arc-20160816; b=ylAHOL44VAVRHiyTd59PElOtEn6VfjUod7fohXoMGMb6vSHuUBajuN16dA4htkEnVY EdSefbteZr0/Xr4TSgUuOhOyIt7nNA6wH4QrzAl/DRMEEtLrZn0ewvM7SYdgWkOq2Jug P4zcsD3BbOC4mlLyNSzapSDEW/WwyG/hYS0K90rfB9pAuvo9iJ7tW2hOaAlJPPUN5R90 nucXJ5RjacUnSE5TndsP1MskESiGpyfUNnk5U1WHjvOKLd/8YF+2wBgjhTjhII1hyGUe abljpUGkjTupYeDeN39d7cew/ZW7juJbghofQDJ0DbEgqd47OkyTp61R/L0eVw041wAL TLpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=gASTRBMskfV+d8k1FQx+uWTSmGqxoHOpmBz5pMJYL9I=; b=PvzFv7WHg4FUYl2YymgT8rYUSi7OB4VPB5XMbp/YpslBM0u8giYG43G+qDPANuGmtI OxvjL/N99ClrCtremIyAxs8rqkKNHJOxB/T3YzWusxyOZw1b5JTmn1Rk5Nh0fsu8tS3O ZaQ9gUCLUBxRnX1OQgXPzmbPBkYM3lRjlOBGPsxmOGKYcFrhWIBk30FKPq+OI1wby7rn lxkMRq6wX1YSCs7Ra2XiOpTBO/WZ9/hApOWhMccaEyDUeTaryzZWw6smNaUAxJipjCKT /qHpNJQfFET4vr9lrUQAdR23JUfGS9nzPdxYZ3sjMM7b9YWlBd8R0FkwoJxOjSPIq8Sj KfdQ== 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 30-v6si1134543pgt.678.2018.08.07.04.02.53; Tue, 07 Aug 2018 04:03:08 -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 S2387931AbeHGNM7 (ORCPT + 99 others); Tue, 7 Aug 2018 09:12:59 -0400 Received: from bran.ispras.ru ([83.149.199.196]:14089 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725966AbeHGNM6 (ORCPT ); Tue, 7 Aug 2018 09:12:58 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id C57BF203C9; Tue, 7 Aug 2018 13:59:09 +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 v2] serial: mxs-auart: Fix potential infinite loop Date: Tue, 7 Aug 2018 13:59:05 +0300 Message-Id: <20180807105905.18264-1-vasilyev@ispras.ru> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180806164346.9986-1-vasilyev@ispras.ru> References: 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 the check so that it is valid for signed and unsigned types. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev --- v2: mistype in patch as result of combination of different fixes. Change comment and leave enum type. --- drivers/tty/serial/mxs-auart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 76aa289652f7..27235a526cce 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -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