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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B68DFECAAD5 for ; Fri, 2 Sep 2022 15:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc: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=j6W5laHjM38Xp3ynj57eXz5DWca3HwHLMpU6Bct11EA=; b=nEiXuwu2uFnLxK 5jblQL+6xgGGt/eVN7D6YYEL8Sqih4MuXPmSiBKEOZIhYrDQSpoe6AXVoDk7Ziq5UaGdO8N+zmIn5 OAMLqr1ddZ0pWniqwU7l63bgK4lQL0uVJjM8EsfkT8opTdyJJX6JkvrtP3stLikeclR1mD7yMcL4Y G3EJ45AzsLPNbtFIR0pDWBdtYQEQYINzh8VTFk29xNYlnraTdKbcmkwwSPrY9uTvo1x2m0W/9gP2Y dBy0piskETboZxWpT9Ls+9ZJvRv/S8eQJaoU2UkyGFnc2lgqJdD5/P4q7JK3AHaviBhpsDbwGXsV4 mUqbS0v3SN5cgp2vR0bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oU8gj-006FTY-8P; Fri, 02 Sep 2022 15:34:33 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oU8gg-006FQa-7k for linux-arm-kernel@lists.infradead.org; Fri, 02 Sep 2022 15:34:32 +0000 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=KN8HpiZT5kVtHo+f+gPTbGT40WqQ8n4rc4nmDa1FEMo=; b=gIbM5iedSMoMMLWMlkTPTlVdWO swurOfOif2A3Kx2WIDh9UbkyeTJ2AT0WhyyOg0ffJpZh1/sOL7Ik8LGexnmw1DFQjtHv7DLUV224p GR+w8LjlirsUiCzg7pmfplKvR+urDwBo3WBie/heaqv8Ml5kc+3+R7zVCpVr2CoBgXctDKVn+qwMS Zi3ZLEKxgYkVy9nBjR1Fler69rb+ACH4D7Cv0vArQbIAKvdQ0pS11s70fJRajhRwJr7GTOZXwgafE bWc04xSop9xjB+tIiwpvQPyIkaP30Am0K50Uu2NePHD2SiLbkBGqqzGT8BoT/HsvA8Nrbouwt0QRk ZhcPCfrA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:34070) 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 1oU8gY-0007ht-Ve; Fri, 02 Sep 2022 16:34:22 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1oU8gX-0004XC-Af; Fri, 02 Sep 2022 16:34:21 +0100 Date: Fri, 2 Sep 2022 16:34:21 +0100 From: "Russell King (Oracle)" To: Andy Shevchenko Cc: Arnd Bergmann , Lee Jones , Linus Walleij , Alyssa Rosenzweig , asahi@lists.linux.dev, Bartosz Golaszewski , Hector Martin , linux-arm Mailing List , "open list:GPIO SUBSYSTEM" , Sven Peter Subject: Re: [PATCH 5/6] gpio: Add new gpio-macsmc driver for Apple Macs Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220902_083430_300368_9ED542D4 X-CRM114-Status: GOOD ( 39.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Sep 02, 2022 at 05:53:25PM +0300, Andy Shevchenko wrote: > On Fri, Sep 2, 2022 at 5:46 PM Russell King (Oracle) > wrote: > > On Fri, Sep 02, 2022 at 04:39:16PM +0300, Andy Shevchenko wrote: > > > On Fri, Sep 2, 2022 at 2:33 PM Russell King (Oracle) > > > wrote: > > > > On Fri, Sep 02, 2022 at 01:37:14PM +0300, Andy Shevchenko wrote: > > > > > On Fri, Sep 2, 2022 at 1:05 PM Russell King (Oracle) > > > > > wrote: > > > > > > On Thu, Sep 01, 2022 at 09:55:23PM +0300, Andy Shevchenko wrote: > > > > > > > > +static int macsmc_gpio_nr(smc_key key) > > > > > > > > +{ > > > > > > > > + int low = hex_to_bin(key & 0xff); > > > > > > > > + int high = hex_to_bin((key >> 8) & 0xff); > > > > > > > > + > > > > > > > > + if (low < 0 || high < 0) > > > > > > > > + return -1; > > > > > > > > + > > > > > > > > + return low | (high << 4); > > > > > > > > +} > > > > > > > > > > > > > > NIH hex2bin(). > > > > > > > > > > > > Is using hex2bin really better? > > > > > > > > > > Yes. > > > > > > > > > > > static int macsmc_gpio_nr(smc_key key) > > > > > > { > > > > > > char k[2]; > > > > > > u8 result; > > > > > > int ret; > > > > > > > > > > > > k[0] = key; > > > > > > k[1] = key >> 8; > > > > > > > > > > > > ret = hex2bin(&result, k, 2); > > > > > > if (ret < 0) > > > > > > return ret; > > > > > > > > > > > > return result; > > > > > > } > > > > > > > > > > > > This looks to me like it consumes more CPU cycles - because we have to > > > > > > write each "character" to the stack, then call a function, only to then > > > > > > call the hex_to_bin() function. One can't just pass "key" into hex2bin > > > > > > because that will bring with it endian issues. > > > > > > > > > > With one detail missed, why do you need all that if you can use > > > > > byteorder helpers()? What's the stack? Just replace this entire > > > > > function with the respectful calls to hex2bin(). > > > > > > > > Sorry, I don't understand what you're suggesting, because it doesn't > > > > make sense to me. The byteorder helpers do not give a char array, which > > > > is what hex2bin() wants, so we end up with something like: > > > > > > > > __le16 foo = cpu_to_le16(key); > > > > u8 result; > > > > > > > > ret = hex2bin(&result, (char *)&foo, 1); > > > > if (ret < 0) > > > > return ret; > > > > > > > > return result; > > > > > > > > This to me looks like yucky code, It still results in "foo" having to > > > > be on the stack, because the out-of-line hex2bin() requires a pointer > > > > to be passed as the second argument. > > > > > > > > Maybe you could provide an example of what you're thinking of, because > > > > I'm at a loss to understand what you're thinking this should look like. > > > > > > So, let's look into the real callers to see, oh wait, it's a single caller! > > > Why can't you simply do > > > > > > ret = hex2bin(&result, (char *)&cpu_to_le16(key), 1); > > > if (ret < 0) > > > return ret; > > > > > > in-place there? > > > > This is not legal C. > > I acknowledged this, sorry. > > > Please can we back up this discussion, and start > > over with legal C suggestions. Thanks. > > Suggestion was given as well, let's create a helper used by apple > stuff and later on we will consider the separate submission for the > (new) specifier. Would it work for you? This sub-thread isn't about the %p4ch specifier. It's about a reasonable implementation of macsmc_gpio_nr(). Extracting from the context above, the original code was: static int macsmc_gpio_nr(smc_key key) { int low = hex_to_bin(key & 0xff); int high = hex_to_bin((key >> 8) & 0xff); if (low < 0 || high < 0) return -1; return low | (high << 4); } I suggested: static int macsmc_gpio_nr(smc_key key) { char k[2]; u8 result; int ret; k[0] = key; k[1] = key >> 8; ret = hex2bin(&result, k, 2); if (ret < 0) return ret; return result; } You didn't like that, so I then suggested: static int macsmc_gpio_nr(smc_key key) { __le16 foo = cpu_to_le16(key); u8 result; int ret; ret = hex2bin(&result, (char *)&foo, 1); if (ret < 0) return ret; return result; } which you also didn't like, and then you suggested something that isn't legal C. So, I then asked you to backup this discussion... As I've made a number of suggestions, and you've essentially rejected them all, I still need to know what you would find acceptable for this, because I'm out of ideas. (I haven't bothered to check whether my last suggestion even works - I am hoping to find out what general style of code you would accept here. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel