From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756405AbbJIRuk (ORCPT ); Fri, 9 Oct 2015 13:50:40 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:58985 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755232AbbJIRui (ORCPT ); Fri, 9 Oct 2015 13:50:38 -0400 X-Sasl-enc: G4Ro9WrJAOnmIG20ZrLxLpUFhitZ3NBtAVBIZ5faua9g 1444413037 Date: Fri, 9 Oct 2015 20:50:36 +0300 From: Sergei Zviagintsev To: David Herrmann Cc: Greg Kroah-Hartman , Daniel Mack , Djalal Harouni , linux-kernel Subject: Re: [PATCH 15/44] kdbus: Simplify bitwise expression in kdbus_meta_get_mask() Message-ID: <20151009175036.GD2189@localhost.localdomain> References: <0a74eb1422ebde6f1df76585451d7839d4d96e23.1444302968.git.sergei@s15v.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, On Thu, Oct 08, 2015 at 04:24:30PM +0200, David Herrmann wrote: > Hi > > On Thu, Oct 8, 2015 at 1:31 PM, Sergei Zviagintsev wrote: > > Replace the expression with more concise and readable equivalent. It can > > be proven by opening parentheses: > > > > r & ~((p | i) & r) == r & (~(p | i) | ~r) == > > (r & ~(p | i)) | (r & ~r) == r & ~(p | i) == r & ~p & ~i > > But why? The current code follows the description, and does exactly > the same. It shows that it merges the "provided" and "implied" masks, > and then extracts the flags that are missing compared to the required > mask. > > I cannot follow why your code is more obvious? The variant I propose has one to one correspondence to the description, but is shorter and has no multi levels of parentheses, thus easier to read, IMO. The comment says "... set of metadata that is not granted implicitly" (which is ~impl_mask), "... nor by the sender" (~prv_mask), "... but still requested by the receiver" (req_mask). We can leave parentheses, i.e. 'req_mask & ~(prv_mask | impl_mask)', but even in this case the original code does one extra bitwise AND. > David > > > Signed-off-by: Sergei Zviagintsev > > --- > > ipc/kdbus/metadata.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/ipc/kdbus/metadata.c b/ipc/kdbus/metadata.c > > index 788b4d9c7ecb..61215a078359 100644 > > --- a/ipc/kdbus/metadata.c > > +++ b/ipc/kdbus/metadata.c > > @@ -1321,7 +1321,7 @@ static u64 kdbus_meta_get_mask(struct pid *prv_pid, u64 prv_mask, > > * the sender, but still requested by the receiver. If any are left, > > * perform rather expensive /proc access checks for them. > > */ > > - missing = req_mask & ~((prv_mask | impl_mask) & req_mask); > > + missing = req_mask & ~prv_mask & ~impl_mask; > > if (missing) > > proc_mask = kdbus_meta_proc_mask(prv_pid, req_pid, req_cred, > > missing); > > -- > > 1.8.3.1 > >