From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 283E7C433ED for ; Sat, 15 May 2021 07:16:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0382F613BE for ; Sat, 15 May 2021 07:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232866AbhEOHRV (ORCPT ); Sat, 15 May 2021 03:17:21 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:2926 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229724AbhEOHRT (ORCPT ); Sat, 15 May 2021 03:17:19 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FhxSd2p97zBtms; Sat, 15 May 2021 15:13:21 +0800 (CST) Received: from [10.174.179.129] (10.174.179.129) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Sat, 15 May 2021 15:15:57 +0800 Subject: Re: [PATCH] char: pcmcia: remove set but not used variable 'tmp' To: Arnd Bergmann CC: Harald Welte , gregkh , , Linux Kernel Mailing List , "zhangyi (F)" References: <20210514062150.3533786-1-yukuai3@huawei.com> From: "yukuai (C)" Message-ID: <7dc2aaca-20d1-46fc-e5a0-312f3fbc7ea4@huawei.com> Date: Sat, 15 May 2021 15:15:56 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.129] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/05/14 14:28, Arnd Bergmann wrote: > On Fri, May 14, 2021 at 8:21 AM Yu Kuai wrote: >> >> Fixes gcc '-Wunused-but-set-variable' warning: >> >> drivers/char/pcmcia/cm4000_cs.c:1053:16: warning: variable ‘tmp’ >> set but not used [-Wunused-but-set-variable] >> >> It is never used and so can be removed. >> >> Fixes: c1986ee9bea3 ("[PATCH] New Omnikey Cardman 4000 driver") >> Signed-off-by: Yu Kuai > > Looks good to me. This was likely written that way at a time when some > architecture implemented inb() as a macro, and ignoring its value > would cause a different warning. > > Since you are already touching this file, can you have a look at this > warning as well: > > drivers/char/pcmcia/cm4000_cs.c: In function 'set_protocol': >>> drivers/char/pcmcia/cm4000_cs.c:569:16: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations] > 569 | pts_reply[i] = inb(REG_BUF_DATA(iobase)); > | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/char/pcmcia/cm4000_cs.c:567:2: note: within this loop > 567 | for (i = 0; i < num_bytes_read; i++) { > > This looks like a preexisting problem that was uncovered by a patch > that is now in linux-next to change the inb() definition once more, > I got a report from the kernel build bot about it after I merged the > patch into the asm-generic tree. It needs a range check on > num_bytes_read, or a Kconfig check to ensure it is not built on > architectures without working inb()/outb() operations. > > Arnd > . > Hi, I'm not familar with the logical here, however, if io_read_num_rec_bytes may get 'num_bytes_read' greater than 4, this loop will cause index out of boundary. It make sense to me to add a range check. Futhermore, since 'num_bytes_read' is ensure to >= 4,I think we can change the loop to: for (i = 0; i < 4; ++i) { xoutb(i, REG_BUF_ADDR(iobase)); pts_reply[i] = inb(REG_BUF_DATA(iobase)); } Thanks Yu Kuai