From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD5BE15FCE7; Tue, 25 Jun 2024 14:08:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719324502; cv=none; b=FJnuHE4olS+zt5CoVE4NiymdHNUjF8fC1fcYfVVg2f7JrDKC6Cf9TqPxq6CV3M83H0BRDat3ECIFYOqD922J6Wwq1R60JrkG5gR9xl+7s+rSnAu2SFx1LZ8x//VD8PRGCEJTMR6JuxyjvdKYain7talbB9t8/aXCsj32xGjPdgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719324502; c=relaxed/simple; bh=MkF7gsbve49E7iOED8XXlHYxiqFod6TCEopF86fOYic=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oACqScrw62Caa9e6FJZlstMtdREJbDU62jcnfXCb55GasWvHg/QRaTo1P0H6vZXVE6VfLAKGxvCapo9zPfn/kJoRhvJR/PKnXKNu90pytsX2zHAelYwiNsZfMsjyjpf3b0JXMgid1+PFeQVP3iDfnP7c4vkcmyOAowWZRLBZb6M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2768DC32781; Tue, 25 Jun 2024 14:08:19 +0000 (UTC) Date: Tue, 25 Jun 2024 10:08:17 -0400 From: Steven Rostedt To: Vlastimil Babka Cc: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Mark Rutland , Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/7] fault-inject: add support for static keys around fault injection sites Message-ID: <20240625100817.078318bf@rorschach.local.home> In-Reply-To: <20240620-fault-injection-statickeys-v2-1-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> <20240620-fault-injection-statickeys-v2-1-e23947d3d84b@suse.cz> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 20 Jun 2024 00:48:55 +0200 Vlastimil Babka wrote: > +static int debugfs_prob_set(void *data, u64 val) > +{ > + struct fault_attr *attr = data; > + > + mutex_lock(&probability_mutex); > + > + if (attr->active) { > + if (attr->probability != 0 && val == 0) { > + static_key_slow_dec(attr->active); > + } else if (attr->probability == 0 && val != 0) { > + static_key_slow_inc(attr->active); > + } > + } So basically the above is testing if val to probability is going from zero or non-zero. For such cases, I find it less confusing to have: if (attr->active) { if (!!attr->probability != !!val) { if (val) static_key_slow_inc(attr->active); else static_key_slow_dec(attr->active); } } This does add a layer of nested ifs, but IMO it's a bit more clear in what is happening, and it gets rid of the "else if". Not saying you need to change it. This is more of an FYI. -- Steve > + > + attr->probability = val; > + > + mutex_unlock(&probability_mutex); > + > + return 0; > +}