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 A08C2C5479D for ; Mon, 9 Jan 2023 12:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233917AbjAIMfm (ORCPT ); Mon, 9 Jan 2023 07:35:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233434AbjAIMfc (ORCPT ); Mon, 9 Jan 2023 07:35:32 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 456F064FA; Mon, 9 Jan 2023 04:35:31 -0800 (PST) Received: from 3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 8B6369FB; Mon, 9 Jan 2023 13:35:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1673267729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JQKaBY79GF+RPE6e93Lg/pYFuxmQLdWNgR8P0RjYoXg=; b=YNe7fL7/NvBT9L6Xe/XKhfiU4deYF+rMcnn0PVQjmP8JXnWJnnkS3k45Axw3ZrVlF835dG mLQILtHhuY/HO+jJTzAgjUYhpeNtQpcwWN3MfskBvly/QmSEDqqw4/g7+wlSqEgBvOWchV r5PnpMP2Ns6mUH0K7HHTxw2Iq3PkYc2/rWu0/FbdurUrmvBL+HOvPeVKDO6aEXB9Rr9GpL AqwASKCUxfm5ylURZ2inKalD18ZZ3BBDbJ2Z/NXdJFJhxakGyaQc0F0cDijDQON8ESHwMG bE99WMg1fhqML2j2+JM6JoPXwjLGUIbtjFqNGWVIEh3KD4iV/aJ4aYBSEOdx9A== MIME-Version: 1.0 Date: Mon, 09 Jan 2023 13:35:29 +0100 From: Michael Walle To: "Russell King (Oracle)" Cc: Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven Subject: Re: [PATCH RFC net-next v2 03/12] net: mdio: mdiobus_register: update validation test In-Reply-To: References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> <20221227-v6-2-rc1-c45-seperation-v2-3-ddb37710e5a7@walle.cc> <37247c17e5e555dddbc37c3c63a2cadb@walle.cc> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <0584195b863b361a4f5c1e27e6c270b3@walle.cc> X-Sender: michael@walle.cc Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Russell, Am 2023-01-03 23:19, schrieb Russell King (Oracle): > On Tue, Jan 03, 2023 at 11:21:08AM +0100, Michael Walle wrote: >> Am 2023-01-03 11:13, schrieb Russell King (Oracle): >> > On Wed, Dec 28, 2022 at 12:07:19AM +0100, Michael Walle wrote: >> > > + if (!bus || !bus->name) >> > > + return -EINVAL; >> > > + >> > > + /* An access method always needs both read and write operations */ >> > > + if ((bus->read && !bus->write) || >> > > + (!bus->read && bus->write) || >> > > + (bus->read_c45 && !bus->write_c45) || >> > > + (!bus->read_c45 && bus->write_c45)) >> > >> > I wonder whether the following would be even more readable: >> > >> > if (!bus->read != !bus->write || !bus->read_c45 != !bus->write_c45) >> >> That's what Andrew had originally. But there was a comment from Sergey >> [1] >> which I agree with. I had a hard time wrapping my head around that, so >> I >> just listed all the possible bad cases. > > The only reason I suggested it was because when looked at your code, > it also took several reads to work out what it was trying to do! > > Would using !!bus->read != !!bus->write would help or make it worse, > !!ptr being the more normal way to convert something to a boolean? IMHO that makes it even harder. But I doubt we will find an expression that will work for everyone. I'll go with your suggestion/Andrew's first version in the next iteration. -michael 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 C2BE1C5479D for ; Mon, 9 Jan 2023 12:36:35 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:Cc:To:From :Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fumm9/F0MNoes68Y10VZtB4dWaj1ggDiI7Q6SzQCV6w=; b=o7xvDBllDt34IvODh2wM2+VUK+ NXxijPrCsjmYtx0dUZm2QK3OEnOsjbFcsD1EpoCcslzI5XbV4+Dpvn+hUC4fAV2mfMbXJodpNk6mu JIGtyBDEyGObCIHDnF0RybI4mNw1fSi60wY8fJuq1V8a5p9NWS0DTu99lkIZX19dKYeplJYT1fQ6Y v+y+8F692rOBaf3OoB4KbtyKP8VNmcqVFoJGOywRNeENjVKmlB/1dIgoITNxwnL22frtB1/89cc7z pz85wHRRGnrKeG0rd6dFAGpIF69CN1zzf883Mh4hep9eO51bA637Jqy7TvOfnF4LA9G1yGMii2cm8 v8QfUHGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pErNJ-001FTS-QF; Mon, 09 Jan 2023 12:35:37 +0000 Received: from 0001.3ffe.de ([2a01:4f8:c0c:9d57::1] helo=mail.3ffe.de) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pErNF-001FRl-J4; Mon, 09 Jan 2023 12:35:35 +0000 Received: from 3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 8B6369FB; Mon, 9 Jan 2023 13:35:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1673267729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JQKaBY79GF+RPE6e93Lg/pYFuxmQLdWNgR8P0RjYoXg=; b=YNe7fL7/NvBT9L6Xe/XKhfiU4deYF+rMcnn0PVQjmP8JXnWJnnkS3k45Axw3ZrVlF835dG mLQILtHhuY/HO+jJTzAgjUYhpeNtQpcwWN3MfskBvly/QmSEDqqw4/g7+wlSqEgBvOWchV r5PnpMP2Ns6mUH0K7HHTxw2Iq3PkYc2/rWu0/FbdurUrmvBL+HOvPeVKDO6aEXB9Rr9GpL AqwASKCUxfm5ylURZ2inKalD18ZZ3BBDbJ2Z/NXdJFJhxakGyaQc0F0cDijDQON8ESHwMG bE99WMg1fhqML2j2+JM6JoPXwjLGUIbtjFqNGWVIEh3KD4iV/aJ4aYBSEOdx9A== MIME-Version: 1.0 Date: Mon, 09 Jan 2023 13:35:29 +0100 From: Michael Walle To: "Russell King (Oracle)" Cc: Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven Subject: Re: [PATCH RFC net-next v2 03/12] net: mdio: mdiobus_register: update validation test In-Reply-To: References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> <20221227-v6-2-rc1-c45-seperation-v2-3-ddb37710e5a7@walle.cc> <37247c17e5e555dddbc37c3c63a2cadb@walle.cc> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <0584195b863b361a4f5c1e27e6c270b3@walle.cc> X-Sender: michael@walle.cc X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230109_043533_813494_CD2915CC X-CRM114-Status: GOOD ( 17.07 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Russell, Am 2023-01-03 23:19, schrieb Russell King (Oracle): > On Tue, Jan 03, 2023 at 11:21:08AM +0100, Michael Walle wrote: >> Am 2023-01-03 11:13, schrieb Russell King (Oracle): >> > On Wed, Dec 28, 2022 at 12:07:19AM +0100, Michael Walle wrote: >> > > + if (!bus || !bus->name) >> > > + return -EINVAL; >> > > + >> > > + /* An access method always needs both read and write operations */ >> > > + if ((bus->read && !bus->write) || >> > > + (!bus->read && bus->write) || >> > > + (bus->read_c45 && !bus->write_c45) || >> > > + (!bus->read_c45 && bus->write_c45)) >> > >> > I wonder whether the following would be even more readable: >> > >> > if (!bus->read != !bus->write || !bus->read_c45 != !bus->write_c45) >> >> That's what Andrew had originally. But there was a comment from Sergey >> [1] >> which I agree with. I had a hard time wrapping my head around that, so >> I >> just listed all the possible bad cases. > > The only reason I suggested it was because when looked at your code, > it also took several reads to work out what it was trying to do! > > Would using !!bus->read != !!bus->write would help or make it worse, > !!ptr being the more normal way to convert something to a boolean? IMHO that makes it even harder. But I doubt we will find an expression that will work for everyone. I'll go with your suggestion/Andrew's first version in the next iteration. -michael _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel