Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp402465pxf; Wed, 24 Mar 2021 07:34:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVcOu717EDLj3qdNukTiYqiXtYP+kBftZKVwd6y5HMf4AqzR5/5ZnXgGFdhW1aMb/fiBTB X-Received: by 2002:aa7:c14a:: with SMTP id r10mr3655752edp.132.1616596485335; Wed, 24 Mar 2021 07:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616596485; cv=none; d=google.com; s=arc-20160816; b=N/5Mk4czut3135BDSx2v/Bg0BeMIyfjdEbD3P4hsc4mfdLEIyXcJdvO5Giy4hTIqnH Bot5tixiHpL7tD/GUPE5RSOklCwFURqpE2P4JQBpHmDqbKojXgQ6B2qHh1Hj0g2qCOA2 E1Zr07MOG9f4uZO1X08uXzrNH9kG4WQ/0jCRhLrW/KN80PBxKcWuiC8VPWK/7E6QUwwS VPJfLxl13qYVYrTsqLQ3LZhzP5HiUG3ze+5Y5Djxr2vUNr3p794MSXFycLXwdHvdxBo+ Pp+wRNcrFVDYv2d7ZuQ12ilvHkxxsDWZ3FeVSLvF5IUgl7YNIpLTFggfFeIu8iGeww92 LsaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=+JlOVWfz8TqF/wBQS24glsjVW0QDxJKlD6E1w1Zdvf8=; b=QvpEVSYkQSbZgb1w6MjfVerHWJdX0mM0XEDc6Lah0Sa7uuPHHSuzSIq08DCjphZQx7 fiBfjz4H9pq0awfb9U9XtpsjTOqklzIghfFEYhAYs/azeDYopSWzGbxdp8S2l49y1fhP XCJ5xtLLuKsgdTHM6HiqhCMxXbkjDfAjw4Nxexby+8irdd2gPmLT0T289ubotgekFz6y kDh/+Ng+DMz1k3DmaLefVtkXvazKm8JOmlG1HSSTynC2+jKTDnoQaCK5z4J3XTd494KU Alk0REABpLv929yjsQVUZyfMSxP9O0O4vz2a0HhX2WJDUhX6v2zECd0HbVPoL+n9eRQR 2LtQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bu13si1841242edb.498.2021.03.24.07.34.21; Wed, 24 Mar 2021 07:34:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236015AbhCXOcU (ORCPT + 99 others); Wed, 24 Mar 2021 10:32:20 -0400 Received: from smtprelay0227.hostedemail.com ([216.40.44.227]:47958 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236330AbhCXOcC (ORCPT ); Wed, 24 Mar 2021 10:32:02 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 32F09182244EB; Wed, 24 Mar 2021 14:32:01 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:800:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3867:3868:3870:3871:3872:3874:4321:4605:5007:6119:6120:7576:7652:7901:7903:8603:10004:10400:11026:11232:11473:11657:11658:11783:11914:12043:12048:12297:12438:12555:12683:12740:12895:13439:13894:14181:14659:14721:21080:21433:21451:21627:21660:21972:21990:30046:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: hill42_1e033b52777b X-Filterd-Recvd-Size: 4973 Received: from [192.168.1.159] (unknown [47.151.137.21]) (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA; Wed, 24 Mar 2021 14:31:59 +0000 (UTC) Message-ID: <382fd12d804ac8e2693f92cf649c4f038f9c022e.camel@perches.com> Subject: Re: [PATCH] amdgpu: fix gcc -Wrestrict warning From: Joe Perches To: Arnd Bergmann , Alex Deucher , Christian =?ISO-8859-1?Q?K=F6nig?= , David Airlie , Daniel Vetter Cc: Arnd Bergmann , Huang Rui , Jinzhou Su , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Date: Wed, 24 Mar 2021 07:31:58 -0700 In-Reply-To: <20210323130430.2250052-1-arnd@kernel.org> References: <20210323130430.2250052-1-arnd@kernel.org> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-03-23 at 14:04 +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > gcc warns about an sprintf() that uses the same buffer as source > and destination, which is undefined behavior in C99: > > drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c: In function 'amdgpu_securedisplay_debugfs_write': > drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c:141:6: error: 'sprintf' argument 3 overlaps destination object 'i2c_output' [-Werror=restrict] > ??141 | sprintf(i2c_output, "%s 0x%X", i2c_output, > ??????| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ??142 | securedisplay_cmd->securedisplay_out_message.send_roi_crc.i2c_buf[i]); > ??????| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c:97:7: note: destination object referenced by 'restrict'-qualified argument 1 was declared here > ???97 | char i2c_output[256]; > ??????| ^~~~~~~~~~ > > Rewrite it to remember the current offset into the buffer instead. > > Signed-off-by: Arnd Bergmann > --- > ?drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 3 ++- > ?1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c > index 834440ab9ff7..69d7f6bff5d4 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c > @@ -136,9 +136,10 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u > ? ret = psp_securedisplay_invoke(psp, TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC); > ? if (!ret) { > ? 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); Perhaps use a hex output like: --- drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c index 9cf856c94f94..25bb34c72d20 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c @@ -97,13 +97,12 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u uint32_t op; int i; char str[64]; - char i2c_output[256]; int ret; if (*pos || size > sizeof(str) - 1) return -EINVAL; - memset(str, 0, sizeof(str)); + memset(str, 0, sizeof(str)); ret = copy_from_user(str, buf, size); if (ret) return -EFAULT; @@ -139,11 +138,9 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u ret = psp_securedisplay_invoke(psp, TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC); if (!ret) { if (securedisplay_cmd->status == TA_SECUREDISPLAY_STATUS__SUCCESS) { - 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, - 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); + dev_info(adev->dev, "SECUREDISPLAY: I2C buffer output is: %*ph\n", + (int)TA_SECUREDISPLAY_I2C_BUFFER_SIZE, + securedisplay_cmd->securedisplay_out_message.send_roi_crc.i2c_buf); } else { psp_securedisplay_parse_resp_status(psp, securedisplay_cmd->status); }