Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2736167rwd; Fri, 16 Jun 2023 07:36:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ467CI43CmmfkXpgKOBY8BtqdlSn+Du5yOT2E54+KOBGDv016D7mJ/mh44pc6LtStrj/MSn X-Received: by 2002:a17:90a:4f04:b0:24d:f739:d62a with SMTP id p4-20020a17090a4f0400b0024df739d62amr1761034pjh.23.1686926182285; Fri, 16 Jun 2023 07:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686926182; cv=none; d=google.com; s=arc-20160816; b=sfjnS2saKn0Lmf+CNBTuvaAsbNu6NzYjxhMqOxDyChZOhMhVn1jF104QoqNHmDHVQJ ptbmWao/39Fs00bQELLKgMpeN4+MIDpPxg9jOu5vTeoRB9NCJY+Kv5ELyxDPlqt8nXdW 3R5Tvat91+cARFNlUmUAARD/12cV2FdOrMkSefw4FiFG0k1/g5/t9LrxZK4tAulL9zGS 3JMNmDHvaE7xfG1xVxtNYmW+btf2WVJtIZ4IgePZkeZC4PY9FJI2StfCXYKbi/02HbPN 4lbDGHZq1fZA0+pV+OJl41SHg6/5sk+zs9wWUI0AWj0UdJtExQuXjpQufpyy2HaUzgtd 6Jqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=f2zoZFIKwsuuxQeUL2pMznNKzcRNsuLpC9DC4rq9Kd4=; b=Mju5HYCa9KyQFWd+kx+6VNIyCN1jQiDKdpAivWDk7dW9pEbaEsTZIZyTWTOrE9LPf1 zBNEFaOWN0/Hk+1BW/J/iBimHEReWSNU6KwVlzH+EAWjAIBK1IS44Ifl4ivXpcrUcPHT YxFPp5/PPi7h0piXmpLpuSFI43Kn+VB/G3D/NpFWekLj61jkwvmRBmi4eqtq/767XSXP IeI3h5CF7+O1zbpF+nief7/RlHFR1K/JDCj5K9aGdxiC8FYmkcUXkIzv8JWJzmaX+owO dyH3J4/Bn4MfNSMcVtzhIYA9EKnlWyQa8T/XWGaitRm0bZqaPnSabJ/xhg7aZ00sQELI zXTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=sRbB+gm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a17090a3e4800b0025bf7aa38ccsi1663302pjm.157.2023.06.16.07.36.08; Fri, 16 Jun 2023 07:36:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=sRbB+gm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238834AbjFPOLS (ORCPT + 99 others); Fri, 16 Jun 2023 10:11:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229965AbjFPOLP (ORCPT ); Fri, 16 Jun 2023 10:11:15 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B12270B; Fri, 16 Jun 2023 07:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=f2zoZFIKwsuuxQeUL2pMznNKzcRNsuLpC9DC4rq9Kd4=; b=sRbB+gm9J+k/h7tGXBoM3O32UK 47bO4ivkcygrgnnqzkqpw1Cx628Y6DZTopXQDGrRufublNCW4vSTL3EGBfsvAQUUwAf8GL+uIN3h3 zkd7/yLGVHuRQ+xSTOKidEs3AQHNgtgHJCuyl57pACxj/l8kWOLSuTN/cg5iw5nNT/pmqGmT0jWDm 3ZS0rOsHB3z4i+6z3K8JyWff2DQxFAkhBLIchXxgS0SYJ8pUiyhxub4pk3oUfnHeN/+xS+P6JI7yz TxtXMFVzXUQXLNtPkGlO0DykpPxXZ6f/oi8sMW3PQPrsSaN5xaNRFEat4dqS20HZ1Ty7J71/I0MnX NDMTixZQ==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:54156) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qAAAP-0005Ia-TA; Fri, 16 Jun 2023 15:11:09 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1qAAAO-0002aH-HU; Fri, 16 Jun 2023 15:11:08 +0100 Date: Fri, 16 Jun 2023 15:11:08 +0100 From: "Russell King (Oracle)" To: Jianhui Zhao Cc: andrew@lunn.ch, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, kuba@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com Subject: Re: [PATCH V4] net: phy: Add sysfs attribute for PHY c45 identifiers. Message-ID: References: <20230616131246.41989-1-zhaojh329@gmail.com> <20230616135455.1985-1-zhaojh329@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230616135455.1985-1-zhaojh329@gmail.com> Sender: Russell King (Oracle) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 16, 2023 at 09:54:55PM +0800, Jianhui Zhao wrote: > >+ struct phy_c45_devid_attribute *devattr = > >+ container_of(attr, struct phy_c45_devid_attribute, attr); > > >+ struct phy_c45_devid_attribute *devattr = > >+ (struct phy_c45_devid_attribute *)container_of(attr, struct device_attribute, attr); > > The two conversions is not same. You're right... > One is convert "struct device_attribute" to "struct phy_c45_devid_attribute", > and another one is convert "struct attribute" to "struct phy_c45_devid_attribute". > The second one must cast "struct device_attribute" returned from container_of > to "struct phy_c45_devid_attribute". ... but this isn't entirely correct. Doing it properly: struct phy_c45_devid_attribute *devattr = container_of(attr, struct phy_c45_devid_attribute, attr.attr); Number one rule with C programming: if you have to cast, you're probably doing something wrong, so always look to see if there's an alternative solution that doesn't involve casts. Casts are one of the reasons why programming errors happen - it stops the compiler being able to perform proper type checking. Always avoid them as much as possible. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!