Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1591459pxb; Fri, 6 Nov 2020 13:53:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOKk5OMR3oR2mB1638P3zxjDwvwgY1aJ5WVSl5SPP48DMLUwCGBD6dRY6oIj5skeZkgnnQ X-Received: by 2002:a17:906:c041:: with SMTP id bm1mr4044840ejb.202.1604699629796; Fri, 06 Nov 2020 13:53:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604699629; cv=none; d=google.com; s=arc-20160816; b=FR/GFpqr1jjJriHxp19ZAjkXc7R9C/76siHClE4a71Ryfz4QAYMPk+n4HfFZ9bPXAX WCd4yWzyd35nVGn0S8+mAKalR6XrnbAHCnXuHKRpsE0g28cihI75Y0QO1wbmShLTmAzB azLAHi5l0Tv5niYw+AORuync3y3qyyrTpa+Ox+28QeDAmH2kOcA3ODw6COUG1ddbS5m5 ECV4TLtg1H/AUhbRkexL/5GDjjcZmUQBkEAULmlpk1rej2XXUsp8PeimrJ0h+Lzo06dG 7guiBjAGeZIdY1p3CJ7oUWfPUvnW7HNADhg/OiXDudmplcv/8p00EZoPQoqkj3dQa602 IJQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=cmDPWB7QbO+W4JkhOIN35AQhJzyf3etN6SzQ4cT7zb0=; b=JYpu9FbTC8pRnhtV/KrMMnOVZA0arJXdTYg3SULcxIYL4ZaPOFrA4oa7JVmbubMQ1O cFj4zCvFxudgYWlFPf/5wianYojNMOJ+aqWptj3vcMo6qxc7pSj15uKiAmYhUMZVID+W uaMAq/axqA1k+M+nayOdUB91R+6FRGWTNlIdqD8bnc4lx93Ue4MbLINDV3CS7ki7Hm/a MJNQHf7Q+YiOGQWip2+98NONtZcyEZkh4/djMIhGbW4u2DlSPlF1QdZRkXEC/PT72k5M NdCTO4jmmuzBcxgF/Bkx7sSovnMf9nuxzwjJnBrgGgu6S5YgYNpOPc2GNPmsAiiHDdSd gSJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t21si1970296edq.546.2020.11.06.13.53.26; Fri, 06 Nov 2020 13:53:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728854AbgKFVuh (ORCPT + 99 others); Fri, 6 Nov 2020 16:50:37 -0500 Received: from smtprelay0176.hostedemail.com ([216.40.44.176]:38860 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728771AbgKFVuN (ORCPT ); Fri, 6 Nov 2020 16:50:13 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 4980E1800F08D; Fri, 6 Nov 2020 21:50:11 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3871:3872:3873:4321:4605:5007:7514:7903:7904:10004:10400:10848:11026:11232:11473:11658:11783:11889:11914:12043:12295:12296:12297:12555:12740:12895:12986:13160:13229:13439:13894:14181:14659:14721:21080:21433:21451:21627:21939:21990:30029:30041:30054:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: rod14_3b0fb74272d5 X-Filterd-Recvd-Size: 3501 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf13.hostedemail.com (Postfix) with ESMTPA; Fri, 6 Nov 2020 21:50:09 +0000 (UTC) Message-ID: Subject: Re: [PATCH] libbpf: Remove unnecessary conversion to bool From: Joe Perches To: Andrii Nakryiko , xiakaixu1987@gmail.com Cc: Alexei Starovoitov , Daniel Borkmann , Martin Lau , Song Liu , Yonghong Song , Andrii Nakryiko , Networking , bpf , open list , Kaixu Xia Date: Fri, 06 Nov 2020 13:50:08 -0800 In-Reply-To: References: <1604646759-785-1-git-send-email-kaixuxia@tencent.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2020-11-06 at 13:32 -0800, Andrii Nakryiko wrote: > On Thu, Nov 5, 2020 at 11:12 PM wrote: > > Fix following warning from coccinelle: > > ./tools/lib/bpf/libbpf.c:1478:43-48: WARNING: conversion to bool not needed here [] > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c [] > > @@ -1475,7 +1475,7 @@ static int set_kcfg_value_tri(struct extern_desc *ext, void *ext_val, > > ????????????????????????????????ext->name, value); > > ????????????????????????return -EINVAL; > > ????????????????} > > - *(bool *)ext_val = value == 'y' ? true : false; > > + *(bool *)ext_val = value == 'y'; > > I actually did this intentionally. x = y == z; pattern looked too > obscure to my taste, tbh. It's certainly a question of taste and obviously there is nothing wrong with yours. Maybe adding parentheses makes the below look less obscure to you? x = (y == z); My taste would run to something like: --- tools/lib/bpf/libbpf.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 313034117070..5d9c9c8d50c9 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1469,25 +1469,34 @@ static int set_kcfg_value_tri(struct extern_desc *ext, void *ext_val, char value) { switch (ext->kcfg.type) { - case KCFG_BOOL: + case KCFG_BOOL: { + bool *p = ext_val; + if (value == 'm') { pr_warn("extern (kcfg) %s=%c should be tristate or char\n", ext->name, value); return -EINVAL; } - *(bool *)ext_val = value == 'y' ? true : false; + *p = (value == 'y'); break; - case KCFG_TRISTATE: + } + case KCFG_TRISTATE: { + enum libbpf_tristate *p = ext_val; + if (value == 'y') - *(enum libbpf_tristate *)ext_val = TRI_YES; + *p = TRI_YES; else if (value == 'm') - *(enum libbpf_tristate *)ext_val = TRI_MODULE; + *p = TRI_MODULE; else /* value == 'n' */ - *(enum libbpf_tristate *)ext_val = TRI_NO; + *p = TRI_NO; break; - case KCFG_CHAR: - *(char *)ext_val = value; + } + case KCFG_CHAR: { + char *p = ext_val; + + *p = value; break; + } case KCFG_UNKNOWN: case KCFG_INT: case KCFG_CHAR_ARR: