Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp348808pxf; Wed, 24 Mar 2021 06:39:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzum34DtZ/WuSphXfiAPt3jnpaqNvuuQM9Xm5tJ+MTqg9zTLOv86GUAHskgSpzOzqT4Y73l X-Received: by 2002:a17:906:acb:: with SMTP id z11mr3763091ejf.193.1616593179761; Wed, 24 Mar 2021 06:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616593179; cv=none; d=google.com; s=arc-20160816; b=wl7I0OSyPub0LO/AbhlPuYwb9mVM7IxfmbpRoFpC3ADIMjx58qqWL8eGtNVB+bUxYl 0KQqDEa3TjyC09mxvCppS47pER3sxiLa71MuMo0cihyisy0LDHptq3Me1WSFMigvGluV +2Ifuahzsrrup30JYzRf1b4KHXa6nvGC6JjongNH1F3Z5S1jyQOt3qsTMhLLH9auBwkQ +cVJ4px9TNpVn7EE8xJFJ3YnsMDaBT52dh2ve3IFlXVDKmtORS2c9dOw6I1fSDjesSN4 5x85cT9JijzPJEF12iJ4bAflHY9UMAKzJIKSov2wH+IttUIwspIO3v5A0KJnm1h+7VVG nJmA== 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=0WRmyuh9UsNlyDIvluwUflwo0QGhXXvG3eCkVwAtWR4=; b=r/5fY9bGhFH3NjRCsv+o+8j+1yBIh2HwsGd6p9o0IX0T2X+++8skw321qULy7wdXGj x8ixMFqG0rmWkbNgewnC4UeV6VP+TyBIOyq/effESx8yIauXvNc/tO62c/GNF2t6vczk 7APVGUMQdXQYW6waggRqwWY90D3BWm9fFDuZSSmLGdVfkVgAhJ03uPZFWFLXNhqZEQ9v Fl6r1ZBQQ+WUlbI/EUFyKU3+PdVqp97Yvjg6QbUufsrHArAcRKR18VwBmK2/AtYTT9h+ 2NZYrkPgin//r+sANEy4G8Vn5QK3O54ij9JL0bNDcGgFQxGqKCiEAW9JusLjx4C72SBo 7j1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QjzaBxVX; 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 t10si1740797edq.420.2021.03.24.06.39.14; Wed, 24 Mar 2021 06:39:39 -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=QjzaBxVX; 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 S235273AbhCXNeg (ORCPT + 99 others); Wed, 24 Mar 2021 09:34:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:47718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235239AbhCXNdr (ORCPT ); Wed, 24 Mar 2021 09:33:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8DD9C61A0B for ; Wed, 24 Mar 2021 13:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616592827; bh=o9N4i7+3noUv0B6lJUnCsQ1a7vxB7qpfn9sOMth9bJM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QjzaBxVXzft4VWeTPw8A5sVm1pW/PtZkCRT8tUJv5DiUqJTMiIZH24/SYzSgH+49I RYAMumLPIjY2zQ+ESslZf5u4gCmhk50vC4lo5vjoExtxSBzYt+ta2WDiqNjxlQ3BxU zsi/Ue6pet0QxobkUplg9lKCmOPEa7MH4MpV2DHIi/iGErPQhP2mVhjGpVvGP4B51l 9jiC88NSVAfsOFAw0UaFTU8JCAJhowbU5k+U8P/B4mXUV7d3vQ1u8NerwFk6IpZNoa sVLamh7L/6a5kgo7M0OaGFn2/lE5nnE3GCfPZ+8e7lQXaZsipwyLi/xKA7w3fRIhlA zHvtDWKLyjdKQ== Received: by mail-oi1-f170.google.com with SMTP id z15so20786999oic.8 for ; Wed, 24 Mar 2021 06:33:47 -0700 (PDT) X-Gm-Message-State: AOAM533wwgyHl066VpmUiYubvA8CqATdyZBOvlnmqNOuMnlioyP9L3Bd eqht2xUsuBe44WEv3DnS2vMTOYgrO7cJAJ/rNYA= X-Received: by 2002:a05:6808:313:: with SMTP id i19mr2358206oie.67.1616592826738; Wed, 24 Mar 2021 06:33:46 -0700 (PDT) MIME-Version: 1.0 References: <20210323130430.2250052-1-arnd@kernel.org> In-Reply-To: From: Arnd Bergmann Date: Wed, 24 Mar 2021 14:33:30 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] amdgpu: fix gcc -Wrestrict warning To: Rasmus Villemoes Cc: Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , Huang Rui , Jinzhou Su , amd-gfx list , dri-devel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 23, 2021 at 4:57 PM Rasmus Villemoes wrote: > On 23/03/2021 14.04, Arnd Bergmann wrote: > > if (securedisplay_cmd->status == TA_SECUREDISPLAY_STATUS__SUCCESS) { > > + int pos = 0; > > memset(i2c_output, 0, sizeof(i2c_output)); > > for (i = 0; i < TA_SECUREDISPLAY_I2C_BUFFER_SIZE; i++) > > - sprintf(i2c_output, "%s 0x%X", i2c_output, > > + pos += sprintf(i2c_output + pos, " 0x%X", > > securedisplay_cmd->securedisplay_out_message.send_roi_crc.i2c_buf[i]); > > dev_info(adev->dev, "SECUREDISPLAY: I2C buffer out put is :%s\n", i2c_output); > > Eh, why not get rid of the 256 byte stack allocation and just replace > all of this by > > dev_info(adev->dev, ""SECUREDISPLAY: I2C buffer out put is: %*ph\n", > TA_SECUREDISPLAY_I2C_BUFFER_SIZE, > securedisplay_cmd->securedisplay_out_message.send_roi_crc.i2c_buf); > > That's much less code (both in #LOC and .text), and avoids adding yet > another place that will be audited over and over for "hm, yeah, that > sprintf() is actually not gonna overflow". > > Yeah, it'll lose the 0x prefixes for each byte and use lowercase hex chars. Ah, I didn't know the kernel's sprintf could do that, that's really nice. I'll send a follow-up patch, as Alex has already applied the first one. Alex, feel free to merge the two into one, or just keep as they are. Arnd