From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAE18C433FE for ; Wed, 12 Oct 2022 12:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229887AbiJLMhy (ORCPT ); Wed, 12 Oct 2022 08:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbiJLMht (ORCPT ); Wed, 12 Oct 2022 08:37:49 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C66C2C707B; Wed, 12 Oct 2022 05:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=JWy5RQWI5KogxEJb2DRzy4LpyNy0j033+Jo3GVosbOA=; b=Fv134si1BGJlyz8/5vUhVpOeHt JGZxF13SrLBknVXU4cPUZV8ynsEWqL0qnDm3KAgqOfYTJck4Mmq3Pdm/+nPsH2q23JRtCZoMm4411 5LHiCQDf5PZOY7IMqEk2DFRRtuhwHkLp+yTeixw+IYp0HEl3omiw2fOMHHGSCtxQhSr4=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1oiazO-001njB-Aj; Wed, 12 Oct 2022 14:37:34 +0200 Date: Wed, 12 Oct 2022 14:37:34 +0200 From: Andrew Lunn To: Christian Marangi Cc: Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Russell King (Oracle)" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pawel Dembicki , Lech Perczak Subject: Re: [net PATCH 2/2] net: dsa: qca8k: fix ethtool autocast mib for big-endian systems Message-ID: References: <20221010111459.18958-1-ansuelsmth@gmail.com> <20221010111459.18958-2-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221010111459.18958-2-ansuelsmth@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > struct qca8k_priv *priv = ds->priv; > const struct qca8k_mib_desc *mib; > struct mib_ethhdr *mib_ethhdr; > - int i, mib_len, offset = 0; > - u64 *data; > + __le32 *data2; > u8 port; > + int i; > > mib_ethhdr = (struct mib_ethhdr *)skb_mac_header(skb); > mib_eth_data = &priv->mib_eth_data; > @@ -1532,28 +1532,24 @@ static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *sk > if (port != mib_eth_data->req_port) > goto exit; > > - data = mib_eth_data->data; > + data2 = (__le32 *)skb->data; > > for (i = 0; i < priv->info->mib_count; i++) { > mib = &ar8327_mib[i]; > > /* First 3 mib are present in the skb head */ > if (i < 3) { > - data[i] = mib_ethhdr->data[i]; > + mib_eth_data->data[i] = le32_to_cpu(mib_ethhdr->data[i]); > continue; > } > > - mib_len = sizeof(uint32_t); > - > /* Some mib are 64 bit wide */ > if (mib->size == 2) > - mib_len = sizeof(uint64_t); > - > - /* Copy the mib value from packet to the */ > - memcpy(data + i, skb->data + offset, mib_len); > + mib_eth_data->data[i] = le64_to_cpu(*(__le64 *)data2); > + else > + mib_eth_data->data[i] = le32_to_cpu(*data2); Are there any alignment guarantees? The old memcpy did not care if the source has oddly alignment. But when you start dereferencing a pointed, you need to be sure those pointers are aligned. You might want to use get_unaligned_le32 and get_unaligned_le64. Andrew