Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp214381ybc; Mon, 18 Nov 2019 23:38:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxnNzot0kfNacKVQMR6sdS5TWdNEPFUkzo5F07ZtvLYHRDx5HYi/B/x+4jrIkiovWFBfe+d X-Received: by 2002:a17:906:c797:: with SMTP id cw23mr32630930ejb.19.1574149136725; Mon, 18 Nov 2019 23:38:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574149136; cv=none; d=google.com; s=arc-20160816; b=N/imNQeZFlh8RtR8W3QrCK+ugNuIUDWqWjv8jPraGbSGjHAby7gkqkqq27ZeysdCUQ 91Yd8oaJpSTsdXJQBMaAQrP0UlzVxc+K6Rm5gtaXvjwASZb0K17YvURzddGpqP6i6hMa Eiu6ZM/jaeXHTP71ZjN35ayKTvvKJEfAXmImmoge6rrdoiVkcORNte2FfljYzyFEQl3B EwMn4UXCbCpK5YgdMSe8OPM9u1wNHHcfCcGts7cn7iYYcs4ctctubfea+HMaHKewzYTf hhaKssRx7DESjfc4zkHnp8xugGggYMVumeZo12h4R0rxpX/7f3zHve4rZmFvi8boN6oR eL0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:authenticated-by; bh=HkXqFSCqLd6x5Rw494X2N20q9QZvayV+/2q1Yf7fzd0=; b=yv+VkD/5WGxvzl8FioZ0m14tN20oWBrdTqwiUkzuPPxIFFYbg02U4Jk0AZWwReIcOi XmreWxa5/i98GQeH6oIsom6pwSDmrjWnkRZE2jNrQwGI2pNH0CDgXjaZrOwcL6ykX9XZ jRTfdNA9occmF3sg7HnapsmRoT22KLb5JRvRP5XAZOiHiL0QlripK+85zDGs6XPaxFH0 dcKIsXcviSay5Sabt7ui+aHevh89p4UeK444rT7im/TNHbOhZTjuSRzWVWhIZzryGrcd Ho0pI3Fz987/fSiup6LjDJVChzVwi/4qSxkwkhA6IS0CT6B69xAjhA5PCjAn0ibW4+Bb cFEQ== 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 n2si12522424ejy.60.2019.11.18.23.38.31; Mon, 18 Nov 2019 23:38:56 -0800 (PST) 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 S1727205AbfKSHeF (ORCPT + 99 others); Tue, 19 Nov 2019 02:34:05 -0500 Received: from rtits2.realtek.com ([211.75.126.72]:57583 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbfKSHeF (ORCPT ); Tue, 19 Nov 2019 02:34:05 -0500 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID xAJ7Xl7w000961, This message is accepted by code: ctloc85258 Received: from RS-CAS02.realsil.com.cn (ms1.realsil.com.cn[172.29.17.3](maybeforged)) by rtits2.realtek.com.tw (8.15.2/2.57/5.78) with ESMTPS id xAJ7Xl7w000961 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 19 Nov 2019 15:33:48 +0800 Received: from localhost (172.29.40.150) by RS-CAS02.realsil.com.cn (172.29.17.3) with Microsoft SMTP Server id 14.3.439.0; Tue, 19 Nov 2019 15:33:46 +0800 From: To: , , CC: , Rui Feng Subject: [PATCH] misc: rtsx: Fix impossible condition Date: Tue, 19 Nov 2019 15:33:45 +0800 Message-ID: <1574148825-2797-1-git-send-email-rui_feng@realsil.com.cn> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.29.40.150] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rui Feng A u8 can only go up to 255, condition n > 396 is impossible, so change u8 to u16. Signed-off-by: Rui Feng --- drivers/misc/cardreader/rts5261.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/misc/cardreader/rts5261.c b/drivers/misc/cardreader/rts5261.c index 32dcec2..8dba0bf 100644 --- a/drivers/misc/cardreader/rts5261.c +++ b/drivers/misc/cardreader/rts5261.c @@ -628,7 +628,8 @@ int rts5261_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk) { int err, clk; - u8 n, clk_divider, mcu_cnt, div; + u16 n; + u8 clk_divider, mcu_cnt, div; static const u8 depth[] = { [RTSX_SSC_DEPTH_4M] = RTS5261_SSC_DEPTH_4M, [RTSX_SSC_DEPTH_2M] = RTS5261_SSC_DEPTH_2M, @@ -661,9 +662,9 @@ int rts5261_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, return 0; if (pcr->ops->conv_clk_and_div_n) - n = (u8)pcr->ops->conv_clk_and_div_n(clk, CLK_TO_DIV_N); + n = (u16)pcr->ops->conv_clk_and_div_n(clk, CLK_TO_DIV_N); else - n = (u8)(clk - 4); + n = (u16)(clk - 4); if ((clk <= 4) || (n > 396)) return -EINVAL; @@ -676,7 +677,7 @@ int rts5261_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, if (pcr->ops->conv_clk_and_div_n) { int dbl_clk = pcr->ops->conv_clk_and_div_n(n, DIV_N_TO_CLK) * 2; - n = (u8)pcr->ops->conv_clk_and_div_n(dbl_clk, + n = (u16)pcr->ops->conv_clk_and_div_n(dbl_clk, CLK_TO_DIV_N); } else { n = (n + 4) * 2 - 4; @@ -721,7 +722,7 @@ int rts5261_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL1, SSC_RSTB, 0); rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, SSC_DEPTH_MASK, ssc_depth); - rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_DIV_N_0, 0xFF, n); + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_DIV_N_0, 0xFF, (u8)n); rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL1, SSC_RSTB, SSC_RSTB); if (vpclk) { rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD_VPCLK0_CTL, -- 1.9.1