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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56EA6C32751 for ; Wed, 7 Aug 2019 14:37:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34E742199C for ; Wed, 7 Aug 2019 14:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387921AbfHGOhm (ORCPT ); Wed, 7 Aug 2019 10:37:42 -0400 Received: from foss.arm.com ([217.140.110.172]:49550 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726829AbfHGOhm (ORCPT ); Wed, 7 Aug 2019 10:37:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3F7CF1570; Wed, 7 Aug 2019 07:37:41 -0700 (PDT) Received: from e107155-lin (e107155-lin.cambridge.arm.com [10.1.196.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8D6603F706; Wed, 7 Aug 2019 07:37:40 -0700 (PDT) Date: Wed, 7 Aug 2019 15:37:38 +0100 From: Sudeep Holla To: Robin Murphy Cc: Philipp Zabel , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] firmware: arm_scmi: Use {get,put}_unaligned_le32 accessors Message-ID: <20190807143738.GB27278@e107155-lin> References: <20190807130038.26878-1-sudeep.holla@arm.com> <1565184971.5048.8.camel@pengutronix.de> <20190807135757.GA27278@e107155-lin> <4e6de98c-833b-a80b-acef-6e88391e80f2@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4e6de98c-833b-a80b-acef-6e88391e80f2@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 07, 2019 at 03:07:39PM +0100, Robin Murphy wrote: > On 07/08/2019 14:57, Sudeep Holla wrote: > > On Wed, Aug 07, 2019 at 03:36:11PM +0200, Philipp Zabel wrote: > > > Hi Sudeep, > > > > > > On Wed, 2019-08-07 at 14:00 +0100, Sudeep Holla wrote: > > > > Instead of type-casting the {tx,rx}.buf all over the place while > > > > accessing them to read/write __le32 from/to the firmware, let's use > > > > the nice existing {get,put}_unaligned_le32 accessors to hide all the > > > > type cast ugliness. > > > > > > > > Suggested-by: Philipp Zabel > > > > Signed-off-by: Sudeep Holla > > > > --- > > > > drivers/firmware/arm_scmi/base.c | 2 +- > > > > drivers/firmware/arm_scmi/clock.c | 10 ++++------ > > > > drivers/firmware/arm_scmi/common.h | 2 ++ > > > > drivers/firmware/arm_scmi/perf.c | 8 ++++---- > > > > drivers/firmware/arm_scmi/power.c | 6 +++--- > > > > drivers/firmware/arm_scmi/reset.c | 2 +- > > > > drivers/firmware/arm_scmi/sensors.c | 12 +++++------- > > > > 7 files changed, 20 insertions(+), 22 deletions(-) > > > > > > > > diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c > > > > index 204390297f4b..f804e8af6521 100644 > > > > --- a/drivers/firmware/arm_scmi/base.c > > > > +++ b/drivers/firmware/arm_scmi/base.c > > > [...] > > > > @@ -204,14 +204,12 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value) > > > > if (ret) > > > > return ret; > > > > > > > > - *(__le32 *)t->tx.buf = cpu_to_le32(clk_id); > > > > + put_unaligned_le32(clk_id, t->tx.buf); > > > > > > > > ret = scmi_do_xfer(handle, t); > > > > if (!ret) { > > > > - __le32 *pval = t->rx.buf; > > > > - > > > > - *value = le32_to_cpu(*pval); > > > > - *value |= (u64)le32_to_cpu(*(pval + 1)) << 32; > > > > + *value = get_unaligned_le32(t->rx.buf); > > > > + *value |= (u64)get_unaligned_le32(t->rx.buf + 1) << 32; > > > > > > Isn't t->rx.buf a void pointer? If I am not mistaken, you'd either have > > > to keep the pval local variables, or cast to (__le32 *) before doing > > > pointer arithmetic. > > > > > > > Ah right, that's the reason I added it at the first place. I will fix that. > > Couldn't you just use get_unaligned_le64() here anyway? Indeed, that's what I found as I wanted to avoid pval, testing now. -- Regards, Sudeep 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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68EC2C32754 for ; Wed, 7 Aug 2019 14:37:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 401AB21E71 for ; Wed, 7 Aug 2019 14:37:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CGaesTqn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 401AB21E71 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wu/6SYwlI/bRvO+K3OBTOeXFWN1uqthrMwtViIyrVlw=; b=CGaesTqnNNZDYq 9BWcvBxE1B0KCAJ6+IhgMQNm2ScqKdaP2WoUvZ01Ygrfbl+dNhMPvTDFpQf6YQfmKfzR3RxbU5yko 1ON/JcSKBbwJYVTVdEm689TZBGjkEHRBnTX/9MY5RuoyDRp1bFWlKk1J6R8BBptrdoi+a5SedJ26b M5GXKYu4Yu/uX8tZfUjSN5H9AAcbyAuM5Ftn6AgvnVcevarVAxyOEY9tWr1S2DrMdmzbrK/fQE5Tc KAeOoNGq270ygC8/vp9Sp1GTrKqi+E82oToxnjZyN3LF3TVzpuEHy83+CVYbWQucBRIke5TTUTkY/ Q5mo8Idt/Y7YTrwpZpHA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hvN4S-0007SG-LG; Wed, 07 Aug 2019 14:37:44 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hvN4Q-0007Rh-2G for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2019 14:37:43 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3F7CF1570; Wed, 7 Aug 2019 07:37:41 -0700 (PDT) Received: from e107155-lin (e107155-lin.cambridge.arm.com [10.1.196.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8D6603F706; Wed, 7 Aug 2019 07:37:40 -0700 (PDT) Date: Wed, 7 Aug 2019 15:37:38 +0100 From: Sudeep Holla To: Robin Murphy Subject: Re: [PATCH] firmware: arm_scmi: Use {get,put}_unaligned_le32 accessors Message-ID: <20190807143738.GB27278@e107155-lin> References: <20190807130038.26878-1-sudeep.holla@arm.com> <1565184971.5048.8.camel@pengutronix.de> <20190807135757.GA27278@e107155-lin> <4e6de98c-833b-a80b-acef-6e88391e80f2@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4e6de98c-833b-a80b-acef-6e88391e80f2@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190807_073742_154220_CEFA8354 X-CRM114-Status: GOOD ( 19.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Philipp Zabel Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Aug 07, 2019 at 03:07:39PM +0100, Robin Murphy wrote: > On 07/08/2019 14:57, Sudeep Holla wrote: > > On Wed, Aug 07, 2019 at 03:36:11PM +0200, Philipp Zabel wrote: > > > Hi Sudeep, > > > > > > On Wed, 2019-08-07 at 14:00 +0100, Sudeep Holla wrote: > > > > Instead of type-casting the {tx,rx}.buf all over the place while > > > > accessing them to read/write __le32 from/to the firmware, let's use > > > > the nice existing {get,put}_unaligned_le32 accessors to hide all the > > > > type cast ugliness. > > > > > > > > Suggested-by: Philipp Zabel > > > > Signed-off-by: Sudeep Holla > > > > --- > > > > drivers/firmware/arm_scmi/base.c | 2 +- > > > > drivers/firmware/arm_scmi/clock.c | 10 ++++------ > > > > drivers/firmware/arm_scmi/common.h | 2 ++ > > > > drivers/firmware/arm_scmi/perf.c | 8 ++++---- > > > > drivers/firmware/arm_scmi/power.c | 6 +++--- > > > > drivers/firmware/arm_scmi/reset.c | 2 +- > > > > drivers/firmware/arm_scmi/sensors.c | 12 +++++------- > > > > 7 files changed, 20 insertions(+), 22 deletions(-) > > > > > > > > diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c > > > > index 204390297f4b..f804e8af6521 100644 > > > > --- a/drivers/firmware/arm_scmi/base.c > > > > +++ b/drivers/firmware/arm_scmi/base.c > > > [...] > > > > @@ -204,14 +204,12 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value) > > > > if (ret) > > > > return ret; > > > > > > > > - *(__le32 *)t->tx.buf = cpu_to_le32(clk_id); > > > > + put_unaligned_le32(clk_id, t->tx.buf); > > > > > > > > ret = scmi_do_xfer(handle, t); > > > > if (!ret) { > > > > - __le32 *pval = t->rx.buf; > > > > - > > > > - *value = le32_to_cpu(*pval); > > > > - *value |= (u64)le32_to_cpu(*(pval + 1)) << 32; > > > > + *value = get_unaligned_le32(t->rx.buf); > > > > + *value |= (u64)get_unaligned_le32(t->rx.buf + 1) << 32; > > > > > > Isn't t->rx.buf a void pointer? If I am not mistaken, you'd either have > > > to keep the pval local variables, or cast to (__le32 *) before doing > > > pointer arithmetic. > > > > > > > Ah right, that's the reason I added it at the first place. I will fix that. > > Couldn't you just use get_unaligned_le64() here anyway? Indeed, that's what I found as I wanted to avoid pval, testing now. -- Regards, Sudeep _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel