Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp22512pxf; Tue, 23 Mar 2021 20:33:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxfBMsA/EGRWPHBMFqe04r1RVfRxK1+CdsVesNaqar5BaZMvetpHR0sfEl65QDDjoLB26B X-Received: by 2002:a17:906:c0c8:: with SMTP id bn8mr1359797ejb.445.1616556828187; Tue, 23 Mar 2021 20:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616556828; cv=none; d=google.com; s=arc-20160816; b=OJxjE/sUwEsVQuAkFJiOTbmHyptn7rr7T2eEU0Qmzd9Gf+rUZckSeohNZZHJkfiY3U rN6kqIiTmrqPQ8AgJ9HF8cpRspnGP5oAo4SH3usUwVDtUcXf0PW8eYpfdTQxry8efsxs HOdTdU+RBpZrP0MoYEV3SYooqIoxdCzezZyQ40IymucQl0Hyw8uQ+MzXAFQm/r/eLByu zbMa6euGVLodP/DYvo6kpiEhlw9RG/mu3RSiBoB94ubgER7wZwkGhhBhLGwGoz5xsEYX 6qiWX4pB6/bx5iWymjcQpNriSKFSgR8BNT/EiCNoV3G8vQD59eMCqi9BD3/m/Raq+MD5 UDXA== 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=BU22F3GylJCKeCQWy9MpZdNcfqLAl6Ije4lLEtEa8GY=; b=dh0qdEClLaGGi9qtRzlTz4LlEYklzifK4bYShxhTzi1tNwexDcbjag2fIcDvf3FPmH ZSfuR8HdqcgAQnQk/cJVlkc2TVPLr4abCkV05Py+OFozi0VSKUQiZ1vP7q0B3zX6omEq qYBu0Xsq4KkxWuzfTTdBWZsTDegouFwBbv3ZwP1wahFPu4jADDvzZDOuLQ7e5SI4BUBP FagacNda6GRVX8hJUsixG7lFNXnHxKYsoyAi1lBa32MDiQxloo4r5YFmE7kEeJrGvuer MIEtoG/VGHomwlVizm2M5v8Bp+i2Iu+/IX6KJ1f7FqUgcwyd0Z3fHmcqWQTbXXxlvpGD QMpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FBzNhcrN; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a17si752860eju.485.2021.03.23.20.33.25; Tue, 23 Mar 2021 20:33:48 -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=@gmail.com header.s=20161025 header.b=FBzNhcrN; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232869AbhCWPeV (ORCPT + 99 others); Tue, 23 Mar 2021 11:34:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232850AbhCWPd6 (ORCPT ); Tue, 23 Mar 2021 11:33:58 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4909C061574 for ; Tue, 23 Mar 2021 08:33:58 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id h6-20020a0568300346b02901b71a850ab4so19841974ote.6 for ; Tue, 23 Mar 2021 08:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BU22F3GylJCKeCQWy9MpZdNcfqLAl6Ije4lLEtEa8GY=; b=FBzNhcrN7thCIaDBITnPorfkjdlRIsHFHiUvYcccyToaj4vMKgH80eNBrdw/Gnw3tB uErAaGg4NWxUEbPUWotD7t8VcUg2Zf71LavYayx6de7yRsxby7ufzIauY1L4URerzG/W VDEJX0K/fIyHR9ieW8q9zQZ5q/rJgB+i3tHbwHNAyJFrWV5I1XM8hngCNi5ltGeUu8nQ VHsKIBJQor4+2XLwUCrJjKejy78IuAt9lL0pP/P4NBQq/2/hsmo48+sDFlRFWywlHZuk reuzf40q/emMKXjMjpt1RpDlBl7CngRU+UDa0YZc1Mh2uERPFssPgsvKilX+DcAb9hwP tRPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BU22F3GylJCKeCQWy9MpZdNcfqLAl6Ije4lLEtEa8GY=; b=f2q7nQCrw0rnUOLw7ZfwMooQ2lS+5MtHk8Julw4kfOgRxO0iKWfD8UaCkXHN6NrObj k0agTLY8P97qjMcdkUMHUjZYDCQkKD6JEXIhJDN9O6dkDNpdn7jhw5//AZF7RS6J9sxb +j6R4uclWxEjcL7RssiYM3JDoFkVLbiPSRzoDiY9+UhbUhyQvJg8oFT4SIuht1y3/gcp 2NKrVMuQ9TfHcsPwaxLMgqVXBXf5SqHANMOghLIaXrF3DDk4jBstK7e7OWSV9T+b3YAY iydfitQUbEI/eI8vj3xAZlkUdYt8HpAROEAUNaevOgYq6/0b0Bpo0lLGG2Pi6TFGv6AH zPyQ== X-Gm-Message-State: AOAM530kt22YLF4fkgOHN7C3nEj/y852V3OoTnOkdt9WXgLDXttrcKml /jDGm9B3tsjZRW/VS3WZQ7PdKjI4luO+e+Fz2tO7qWP3 X-Received: by 2002:a05:6830:408f:: with SMTP id x15mr5048220ott.132.1616513638090; Tue, 23 Mar 2021 08:33:58 -0700 (PDT) MIME-Version: 1.0 References: <20210323130430.2250052-1-arnd@kernel.org> In-Reply-To: <20210323130430.2250052-1-arnd@kernel.org> From: Alex Deucher Date: Tue, 23 Mar 2021 11:33:47 -0400 Message-ID: Subject: Re: [PATCH] amdgpu: fix gcc -Wrestrict warning To: Arnd Bergmann Cc: Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , Jinzhou Su , Arnd Bergmann , LKML , Maling list - DRI developers , Huang Rui , amd-gfx list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Applied. Thanks! Alex On Tue, Mar 23, 2021 at 9:04 AM 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); > } else { > -- > 2.29.2 > > _______________________________________________ > amd-gfx mailing list > amd-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx