Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp675135img; Wed, 20 Mar 2019 08:33:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDeJ2tB/cNqobBgk9GSKaBZ9SqJE0BiG0PfKDEGiyXwGIV7Ka+crVAExluWYUJ7/PYs0Zl X-Received: by 2002:a63:5266:: with SMTP id s38mr8004851pgl.333.1553096027230; Wed, 20 Mar 2019 08:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553096027; cv=none; d=google.com; s=arc-20160816; b=GS1TeKasLAO/smZUPMZsG/KVdSn9MMhX90CFaIZbFvkLQxU5Uzgo0pBEkWuHQ8Y8u7 lVdgLFLBXDzdM1A7ZytmpjiGxcLZmLuOeNJ5KbmEjquib3NnMeG8Kop6/zAaDm6blK7T BH6UZIMu2PHfOocmCldiBji2lFhgcPdBhWn5GMNx6u1CgB5PP+DjKGfdl5lSW7t5rIkf AbnrkPWD4+vMS8fXZh8FgV++hnFuzyow14fdhnHqfTjWV4gFs/ndcWMM37y5GU3nH+vT akdfpbv3xJot3AMEbvu8qzXohKn4HIO95EIAwJIXdmrcP/vnQ3/bZd83UsgfZhT4dayk fu9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=NOsFP3DDoy1KAUPRkqHaAbQaMgIKB2bS4OMcK0PDoEg=; b=D83k9yX/NsOpIGt6oKyqkNreVQCx0sGKiwDzBpw7amXVdTEhkPYoof2h/+ooxAcfY9 OWgbsOVgJW1JDq2DsIhbak8EE5Dme9ePPZ6PDzbserGButdu8UtkWDwXuq7ayCl7b+4l dpDJqS8gEgjLhGmbTKwns/89CgJNHMxjFL4L6mFuXuhXJESsbCck05Ivep1NSp1rU+HJ +77TV7je+oXpOvQOgy/TRA6hjRMD4lrhYD5WD+HcRsu1t55grbnnLcuPBpCc3W0m+WLC vte4N9ILNSmosuZ4Q2OagXg+UF5tQekMExr3hQ8ER0OnKKRCwUEFoJlfgaIeA5L/liIx q3Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mEx0lshX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x22si2058010plr.111.2019.03.20.08.33.31; Wed, 20 Mar 2019 08:33:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mEx0lshX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726616AbfCTPct (ORCPT + 99 others); Wed, 20 Mar 2019 11:32:49 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:40813 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbfCTPct (ORCPT ); Wed, 20 Mar 2019 11:32:49 -0400 Received: by mail-ed1-f66.google.com with SMTP id h22so2368555edw.7 for ; Wed, 20 Mar 2019 08:32:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=NOsFP3DDoy1KAUPRkqHaAbQaMgIKB2bS4OMcK0PDoEg=; b=mEx0lshXZDnd23fljYVqbvWPmSHcIlyZ1MUM1GNJRnBOo8UnT7NgycC5z7PpJ0i01t HZSfY9zwoW5+kPgoA62hWRMBogiIzsameqX35pYc0AVV75+/zAgxTXzDmuNf8FWLK0SH exdI0gxZWFgwAWEpV+UT7zN+/ug4UkzNsnBt8d/BdHDGpZsCT6mUP/EAG+0Z9eoNPbOq qO9ONI27Wp5WqrKkWW2UcK2LQlFMPsDXx7qgxRNTCwRd/xG5q67H8II0reesMv2CkqBa rq4U8dzZZvtwAjzLxJZ6TFjHE8x6tP6g3ZNH20IJfHoC0v04RL/H+OahUGLtDDuwqNGA t55Q== 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:content-transfer-encoding; bh=NOsFP3DDoy1KAUPRkqHaAbQaMgIKB2bS4OMcK0PDoEg=; b=mYxHH5APQ+tBbisSyjRvI1tq1318igGhIXs1Biz4oFxxqVtyarIdBbC953c5MXzHu4 TgaQOgf3vIVAU38MhKB9+gsnE8Fy6RmXkBJIGaaoP7xjn71pIRsKETGAvz4fpmHUNIQ1 CLMV17zCoNcszMgNcSWnjhwU8RMfwUqhredQYKUx7t+gC1M8PKD+LcWpJK/zJENTjNTU mrhSJd6mgM8q0b0x1FkNql8oVwLr/ZP1NZVtEpi3pUbfn1+hmuQmnUduEqVKRqxRb/5F frXt149I4E/mh4n5JQ7ToMKDnn3kDyTUl66fdd+G7dSb0n0I+h/qYFPQBVPlw1UijdL7 +p3g== X-Gm-Message-State: APjAAAVpXp5w6TbyXqHrp+lLFLtZLU7+KNW/7XidlB67AkxovzduN89y SF/Or9f0bNNXOBKHEdNqcWMgVhZ2cmMwoJBqXaKkqQ== X-Received: by 2002:a50:aeec:: with SMTP id f41mr3012255edd.279.1553095966726; Wed, 20 Mar 2019 08:32:46 -0700 (PDT) MIME-Version: 1.0 References: <20190320005406.GA16412@archlinux-ryzen> <20190320043440.GA23335@archlinux-ryzen> <63518f1f-b808-77b0-aac6-ee1ece669c4b@amd.com> In-Reply-To: From: Stephen Hines Date: Wed, 20 Mar 2019 08:32:35 -0700 Message-ID: Subject: Re: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c To: "Koenig, Christian" Cc: Nathan Chancellor , "Pan, Xinhui" , "Deucher, Alexander" , "Zhou, David(ChunMing)" , "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "clang-built-linux@googlegroups.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Resending as plain-text to rest of list. Steve On Wed, Mar 20, 2019 at 7:58 AM Stephen Hines wrote: > > Why are there 2 different enums for this same thing at all? By casting, y= ou are reducing type safety in the kernel, which can cause bugs later (shou= ld the two enums diverge in encoding). In my opinion, the proper solution i= s to remove one of the enums or provide an explicit helper that does the co= nversion (along with assertions for handling any unexpected cases). The hel= per function should not be doing a direct cast, since a bug could change th= e integer value of one (or both) of these enums so that they don't match up= . > > Thanks, > Steve > > On Wed, Mar 20, 2019 at 2:37 AM Koenig, Christian wrote: >> >> Am 20.03.19 um 05:34 schrieb Nathan Chancellor: >> > On Wed, Mar 20, 2019 at 01:31:27AM +0000, Pan, Xinhui wrote: >> >> these two enumerated types are same for now. both of them might chang= e in the future. >> >> >> >> I have not used clang, but would .block_id =3D (int)head->block fix= your warning? If such change is acceptable, I can make one then. >> >> >> >> Thanks >> >> xinhui >> >> >> >> >> >> -----Original Message----- >> >> From: Nathan Chancellor >> >> Sent: 2019=E5=B9=B43=E6=9C=8820=E6=97=A5 8:54 >> >> To: Deucher, Alexander ; Koenig, Christian= ; Zhou, David(ChunMing) ; P= an, Xinhui >> >> Cc: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; l= inux-kernel@vger.kernel.org; clang-built-linux@googlegroups.com >> >> Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c >> >> >> >> Hi all, >> >> >> >> The introduction of this file in commit dbd249c24427 ("drm/amdgpu: ad= d amdgpu_ras.c to support ras (v2)") introduces the following Clang >> >> warnings: >> >> >> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit con= version from enumeration type 'enum amdgpu_ras_block' to different enumerat= ion type 'enum ta_ras_block' [-Wenum-conversion] >> >> .block_id =3D head->block, >> >> ~~~~~~^~~~~ >> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit con= version from enumeration type 'enum amdgpu_ras_error_type' to different enu= meration type 'enum ta_ras_error_type' [-Wenum-conversion] >> >> .error_type =3D head->type, >> >> ~~~~~~^~~~ >> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit con= version from enumeration type 'enum amdgpu_ras_block' to different enumerat= ion type 'enum ta_ras_block' [-Wenum-conversion] >> >> .block_id =3D head->block, >> >> ~~~~~~^~~~~ >> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit con= version from enumeration type 'enum amdgpu_ras_error_type' to different enu= meration type 'enum ta_ras_error_type' [-Wenum-conversion] >> >> .error_type =3D head->type, >> >> ~~~~~~^~~~ >> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit con= version from enumeration type 'enum amdgpu_ras_block' to different enumerat= ion type 'enum ta_ras_block' [-Wenum-conversion] >> >> .block_id =3D info->head.block, >> >> ~~~~~~~~~~~^~~~~ >> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit con= version from enumeration type 'enum amdgpu_ras_error_type' to different enu= meration type 'enum ta_ras_error_type' [-Wenum-conversion] >> >> .inject_error_type =3D info->head.type, >> >> ~~~~~~~~~~~^~~~ >> >> 6 warnings generated. >> >> >> >> Normally, I would sent a fix for this myself but I am not entirely su= re why these two enumerated types exist when one would do since they have t= he same values minus the prefix. In fact, the ta_ras_{block,error_type} val= ues are never used aside from being defined. Some clarification would be ap= preciated. >> >> >> >> Thank you, >> >> Nathan >> > Hi Xinhui, >> > >> > Yes, explicitly casting these six spots to int would resolve this >> > warning. >> >> Another question is if it is such a good idea to just silence the warnin= g? >> >> Maybe add a amdgpu_ras_error_to_ta() helper to do this casting? >> >> When the enums drift away from each other then we can still add warnings >> to that helper to make sure we don't accidentally cast invalid values >> around. >> >> Regards, >> Christian. >> >> > >> > Thank you for the quick response! >> > Nathan >> >> -- >> You received this message because you are subscribed to the Google Group= s "Clang Built Linux" group. >> To unsubscribe from this group and stop receiving emails from it, send a= n email to clang-built-linux+unsubscribe@googlegroups.com. >> To post to this group, send email to clang-built-linux@googlegroups.com. >> To view this discussion on the web visit https://groups.google.com/d/msg= id/clang-built-linux/63518f1f-b808-77b0-aac6-ee1ece669c4b%40amd.com. >> For more options, visit https://groups.google.com/d/optout.