Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp397237pxf; Wed, 24 Mar 2021 07:29:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJhmniRRi6ThxrR+eNhoL2ekpPswrREmja2Vfk2wArzEInQsxGKHEGvzPzVqGD9bPGbMJP X-Received: by 2002:aa7:d4cb:: with SMTP id t11mr3717884edr.202.1616596173874; Wed, 24 Mar 2021 07:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616596173; cv=none; d=google.com; s=arc-20160816; b=hPronDE/dgAZSo493h4BeAUW0jjnXJTLk01GYPXNco567pJMzBRgSbk/Z8E+Eh9RWL KUk5JxKMsn/wO37BLXMCYwoDPzZSD2lkUxd1cpzFxTuj9Z+MGF/FdwwptKUAolc/jnXg EHT5lRutcOQlahsnIjdc1LErVk2tnU52afkHBkoNSX2ILpiXwbtBDlQnO0q2lTTPi5mZ 71TNcjCmLoaMV97DgNlv9S4DXs7PHfeBDbyf6cJI1JpHsvgJn1CSFEHDJlh5bbBGchYf o/2TQybUQq/EipGuQXp+pGJ5wb4tvV65M64/q+Jv62HFxrIPkgdcCmP2OkP1tTZs5GIP a+rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=b1amN0bxPErE+3PSR56bUNKUrEUh2jFFnX4QAmt7suU=; b=ISKBSNYiqQztN4iHlWSCjpNE122+Yza9BS+/DDRZ93kowTS1Vaq5ZpFlHkxWB88bGw tPDrQnYjPtGek9QkxrmYQWQ3uRWSJgKe0TUCphjw3FDprhf3rauknvQjxy7R9FFkbAo2 xf5zYzGtbtuvKDCzqDi8fsjOBfWBD/X4YGows3wpaL6w5FFR/3d6FQX5tVgHWlCAAhEE rEEvhNUs1bhNubUu8q3kfLzcSOtvDZDOh9yxPgcPEJayBeT+hAUWWz/4azx40FXIO+Af F0jUWSMkzHDPE7zkdWKYSXMqyZ0bbVefKtuDgF/ssTiQDcKSFqotRr8+If+vLUFZqnJD 4iaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MyC7FumJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si2050203edd.118.2021.03.24.07.29.10; Wed, 24 Mar 2021 07:29:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MyC7FumJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236218AbhCXO0Z (ORCPT + 99 others); Wed, 24 Mar 2021 10:26:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:35070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236201AbhCXO0F (ORCPT ); Wed, 24 Mar 2021 10:26:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C553E61A07; Wed, 24 Mar 2021 14:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616595964; bh=e+83tN45oub7t57k1wySmI/GI/W3QxhArTyYJ/WCdjI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MyC7FumJwuWCuJF5e7NsK+sJDyWQmivi5cxuBsYwdDMeMr+uf+dSvIBzCWYgF45Um dTVykwVywevc+Al3FxUQD17nbqDY4u85pIJV3Zf2IoFWnegJ3vrRKH93WpbKNLP/Al Wjw4EbRDXiFwYoYowrfLKXtAlK3eFCLdxzgWICe6/JDsJNQ9TLMwExtjV2aU4bLPZy 8igI8jLJyV2LyBF3oNxCkR39aO0d9C/PIgrLV9SLzpwxU0mrAIiK7QQ59syd9pvSMz Ue1BIfKzUxRvdDdObymdq1uWxnOcMJ1jpbUSlnv4CN0PZm6YKZOuiIYwDyKRZ2sAlL JT9Ei62zXP9Ww== Received: by mail-ot1-f51.google.com with SMTP id 31-20020a9d00220000b02901b64b9b50b1so23154050ota.9; Wed, 24 Mar 2021 07:26:04 -0700 (PDT) X-Gm-Message-State: AOAM532Bx4PIqlMVPj6xeprk+451051T0nuw6ttwoJ+6wkDySRui79xH ePJWvnv8Krg5AuiWgKXZRZBjqY1jx8xDH94HKNc= X-Received: by 2002:a05:6830:148c:: with SMTP id s12mr3564868otq.251.1616595964114; Wed, 24 Mar 2021 07:26:04 -0700 (PDT) MIME-Version: 1.0 References: <20210324130731.1513798-1-arnd@kernel.org> In-Reply-To: From: Arnd Bergmann Date: Wed, 24 Mar 2021 15:25:47 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] [v2] hinic: avoid gcc -Wrestrict warning To: Rasmus Villemoes Cc: Bin Luo , "David S. Miller" , Jakub Kicinski , Networking , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 2:29 PM Rasmus Villemoes wrote: > On 24/03/2021 14.07, Arnd Bergmann wrote: > > > if (set_settings & HILINK_LINK_SET_SPEED) { > > speed_level = hinic_ethtool_to_hw_speed_level(speed); > > err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN, > > - "%sspeed %d ", set_link_str, speed); > > - if (err <= 0 || err >= SET_LINK_STR_MAX_LEN) { > > + "speed %d ", speed); > > + if (err >= SET_LINK_STR_MAX_LEN) { > > netif_err(nic_dev, drv, netdev, "Failed to snprintf link speed, function return(%d) and dest_len(%d)\n", > > err, SET_LINK_STR_MAX_LEN); > > return -EFAULT; > > It's not your invention of course, but this both seems needlessly harsh > and EFAULT is a weird error to return. It's just a printk() message that > might be truncated, and now that the format string only has a %d > specifier, it can actually be verified statically that overflow will > never happen (though I don't know or think gcc can do that, perhaps > there's some locale nonsense in the standard that allows using > utf16-encoded sanskrit runes). So probably that test should just be > dropped, but that's a separate thing. I thought about fixing it, but this seemed to be a rabbit hole I didn't want to get into, as there are other harmless issues in the driver that could be improved. I'm fairly sure gcc can indeed warn about the overflow with -Wformat-truncation, but the warning is disabled at the moment because it has a ton of false positives: kernel/workqueue.c: In function 'create_worker': kernel/workqueue.c:1933:55: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size between 3 and 13 [-Werror=format-truncation=] 1933 | snprintf(id_buf, sizeof(id_buf), "u%d:%d", pool->id, id); Arnd