Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4227558pxf; Tue, 23 Mar 2021 06:06:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxs3ZZvlAkNip7hdcERmLdFPzr9kyvikpvbcL6/oNWMhHFpPiBi69vsxBTH76N3/GnVSjjq X-Received: by 2002:a17:906:8308:: with SMTP id j8mr4670675ejx.339.1616504819174; Tue, 23 Mar 2021 06:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616504819; cv=none; d=google.com; s=arc-20160816; b=nxZWXYCZin8dQcEHT5yU6ZvMGC+p7UhbrpgdCyEqioSLYbubH9/O6+SdUm/3HDtob7 qizW+cbgj1hvs/x3yvh+S8c2xHh1Q82DozwW2OwJV2CeeKyOHq9AKGhvel7YR/qNziY2 XS1aHu6raFDDnLbY2bDC/RD58ZEjpyTUYALk1aVllbrUBc6Xm1GG9UYMRH9Fw3FFRazs UXkA/ou7qLo0FEvEo8dmIxnL+GaqhF8zi1rqGnlsuMHdkmnWyQU2S83MPal/68j/EHN0 KwRZr9CbG6D75zrjmIzpnORNZwzAQF3yMziVheiRAB33Z77emwaLHkeZFNaUdx3V++Jn aKjQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=UUprwFSP6P6FmFJSiJhw3SYxUk+L7HkdRufUjxmpxdY=; b=mWJZvitp5k4OgLQIpBPKg2d74WoNQVIkmkaMfOGjxvwQdGsdfP2Rx2s4b1CcDU/RX7 h1mj8oJk8PM3Nk9bUa2dOHvOy8Ofj32aDRYIRT5SzEMlGK7gSM9LIuq8OO+6rlLh8rQl tcCdhFGXcpuTPQA/M55y8nIbsE4oemoeLfijhcT6vw3L4/Ers7NlcUrbGf0viPfR7CxG RYLQAr1cS5BVKzYeOlHoMyvlWjdN0OvRoH5qNjK1NfVglLE6y0UkQ0VfCzXFPgGc/hr4 LqkBWogEUVU9FGJBh0jiiy8aiwZlFf98Q7GjqULhkciUN6eEb+OsDyBNdaxaDRpI5jGS IBBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NSVZHMS2; 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 i17si15361864ejo.365.2021.03.23.06.06.27; Tue, 23 Mar 2021 06:06:59 -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=NSVZHMS2; 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 S231328AbhCWNEr (ORCPT + 99 others); Tue, 23 Mar 2021 09:04:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:42920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231322AbhCWNEf (ORCPT ); Tue, 23 Mar 2021 09:04:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D79BB619B6; Tue, 23 Mar 2021 13:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616504674; bh=q6NHsIW3BnA5mhThORhjcdH3DG7oZJ3fYXk3ohPq4IE=; h=From:To:Cc:Subject:Date:From; b=NSVZHMS2Sa44doHHUf+7S7yQgC3c7fmn8mqentdeLVYtyu9W1ptJa2pLE79Fdw4T1 x25sJWLjI8q72sGiXXjws1uxQ+Stxy21a1AGhFnFNQ71UmNVqiq17cLSooefF8iLZh DpQ8dPBai9dvRSoVgcW/hM+fEuLE6l21P9PUtsIJ+zZb08BftvHsYvXj1DXNCLCGxD DdFhaiPPrSeskOliAZMdENIJIVbTLGsDMajQLPthjqfTbvw0LACdqTKMhCKer76HYR Mjcz7piID8kj8USw42m8caU00xxjmYn/DiRMbafuxX6EVK/6pitlIivY+HIxUUY0qm mLIpyBIPjsJ3Q== From: Arnd Bergmann To: Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , 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 Subject: [PATCH] amdgpu: fix gcc -Wrestrict warning Date: Tue, 23 Mar 2021 14:04:20 +0100 Message-Id: <20210323130430.2250052-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } else { -- 2.29.2