From patchwork Tue Dec 19 17:18:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 181142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2095482dyi; Tue, 19 Dec 2023 09:24:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfag97B8aQvUGdXrKQiyLxiOXtki4UWooh9zaw47oauNmuuHf0Ba4N1dl+4+qHQgXkm0HW X-Received: by 2002:a05:620a:14a7:b0:77d:a04d:24ef with SMTP id x7-20020a05620a14a700b0077da04d24efmr14521516qkj.74.1703006664377; Tue, 19 Dec 2023 09:24:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703006664; cv=none; d=google.com; s=arc-20160816; b=On68Dv6pVUJzz5ZdvS3GyJCoYqEOP7gIdkGkMaqQRWyUmY7sC99jTqibo9DNEsNfer YxvWOgkj/Gt4w0lVypWCR70kIc0w7jEMboylKQwNKL87DiDw5biDD5W2GtbwSFzAjdir bzHuwgKtq1lUoeyPvk1QRj0mJxE1Nr6Qz6QMvx33n32AfwouKyMRr1b9iYwrrtDKW72e hjrDTq4WUfDOTOT8hW1HC57vs7P0iFQlBZA1SWA+W2jD33soGl83CqhoboikCtshqpZw oh/fvMeMRAAxK7N2wVOjIrzdJTlLkUyZCooDkuEkJau+DXcG5DiGu0oMS3SLQSMO0qxW aHfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:cc:to:from:dkim-signature; bh=eAovb+UcCr8c4+yXpiGUDUECK8pQrI3Ofw2ziL8xaHg=; fh=XmY8az1z5a+LjrZQ1DQahIeB3Uro2SuOHb+6mIYcxXo=; b=Yq1f+vQPPTTB94m7QumijkDrQaqQ7tQEPJ/a1QpYPybwCHdrUlQJojplh5FgPlob1E CBqS7rVD6iPrV6Rv+nr9GOw++REYaXHG3SoX0JD/yxntSdREAdo66D6NjnGhbxI5yxuI MX3Q7B4bQdjEwq48S6A5yp1R2s27kVgGTO4yjf1zQh+ea+bNhUbQaqpFIIvobScjbJeD kClEXTAA1R6nEic80AS72QGatdmXmzmutKF5j/1jrmIuOzWpX3n/qvmuYNQfMZXQqsmW Ry14IzSaoce6ump4WIAx5xlK4lTgycwlguZGeSp3Y+GawW2TjBgkPWyPIiAHnS2AuLak yS6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=xb4NbYgN; spf=pass (google.com: domain of linux-kernel+bounces-5682-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5682-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a20-20020a05620a439400b0077f75b710ccsi14294239qkp.399.2023.12.19.09.24.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 09:24:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5682-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=xb4NbYgN; spf=pass (google.com: domain of linux-kernel+bounces-5682-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5682-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C91D1C24F5C for ; Tue, 19 Dec 2023 17:24:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA97240BE6; Tue, 19 Dec 2023 17:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="xb4NbYgN" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E97B71CA89; Tue, 19 Dec 2023 17:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Cc:To :From:subject:date:message-id:reply-to; bh=eAovb+UcCr8c4+yXpiGUDUECK8pQrI3Ofw2ziL8xaHg=; b=xb4NbYgNCU3y5gAWSAmZIKnYEA mxGt9n6Mq740/FU1jviVnXzo7T+ziUKk9/z07smCh+nR9TaaLoZGGv3UE5jHqPpkhBhQk7K8Gc3Zj 2+IGINBIdLTNN0FmjmOnbkUZfHVO207RCm3g7ws2TgkSFNqB3wPLcdDZTStMp/uGcw0s=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:40128 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rFdkV-0007Ao-SB; Tue, 19 Dec 2023 12:19:20 -0500 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org, jringle@gridpoint.com, kubakici@wp.pl, phil@raspberrypi.org, bo.svangard@embeddedart.se Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve , Andy Shevchenko Date: Tue, 19 Dec 2023 12:18:57 -0500 Message-Id: <20231219171903.3530985-14-hugo@hugovil.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231219171903.3530985-1-hugo@hugovil.com> References: <20231219171903.3530985-1-hugo@hugovil.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Level: X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -0.0 T_SCC_BODY_TEXT_LINE No description available. Subject: [PATCH 13/18] serial: sc16is7xx: use in_range() for DT properties bound checks X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785731916224676761 X-GMAIL-MSGID: 1785731916224676761 From: Hugo Villeneuve Improve code readability and efficiency by using in_range() when checking device tree properties bound. Suggested-by: Andy Shevchenko Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/sc16is7xx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 133538f91390..29089b11f6f1 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1398,7 +1399,7 @@ static void sc16is7xx_setup_irda_ports(struct sc16is7xx_port *s) struct device *dev = s->p[0].port.dev; count = device_property_count_u32(dev, "irda-mode-ports"); - if (count < 0 || count > SC16IS7XX_MAX_PORTS) + if (!in_range(count, 0, SC16IS7XX_MAX_PORTS + 1)) return; ret = device_property_read_u32_array(dev, "irda-mode-ports", @@ -1425,7 +1426,7 @@ static int sc16is7xx_setup_mctrl_ports(struct sc16is7xx_port *s, struct device *dev = s->p[0].port.dev; count = device_property_count_u32(dev, "nxp,modem-control-line-ports"); - if (count < 0 || count > SC16IS7XX_MAX_PORTS) + if (!in_range(count, 0, SC16IS7XX_MAX_PORTS + 1)) return 0; ret = device_property_read_u32_array(dev, "nxp,modem-control-line-ports",