Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5105763pxb; Thu, 14 Oct 2021 19:35:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUvwRVLC0lzNs6ZvOpxVS7+IoIg9LhkGNYNlFfQSky5PqHPtLZDM/AbvjwH/ZbSrSDvirv X-Received: by 2002:a17:907:7ba8:: with SMTP id ne40mr3342683ejc.335.1634265358559; Thu, 14 Oct 2021 19:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634265358; cv=none; d=google.com; s=arc-20160816; b=QgHAmG0JV4pWJdlyJ76wSLEL0P94HvXYdIsw1XaxW/rbB03qKDXc+kaiZdQsAhKddK Ja9FUwNkJ99EDBBlyYGYsR5w3YikAFWsSi4uxIyBnhetZPQSLUdpP3G9zLerKCIORhX5 O3UmzwcPmIEAAVeDDHFzmtA/rbGPVFGC7yNMKcsBRTTt4YR2iDuxqvoMdSo7MjaYD2uZ l6gKM8Q//PEVNebT/thfcuwWiXh1BG99ev9+jZ9QJoAn3JR6IkGaEPLIEUdjU2jbbsvz m7CWlRaFPvqZSBfYUX0Q3fTAmeTQ26tjRHf3ncMV8naLXHB8nZEPyifDxMcWEsimQi09 O+Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jI0siKnxYryfR0Wrdx331NbLBs00Z1e/lOmM3iHWBvg=; b=Xnlqaz9YHj/lIiAplUDM+RqLcjqw+d8JtSnG6lPx5K26Wq/UjnFmBmaBxBkKCKjvjY I4RI3QqaPLw4jf5/t1cH9sv8hEXTDKWU1n1w73MH55o/WUhNN5rRM8+O9fGG4egZ6jJ3 AdJHl7S2ZPDBsNWbtVE0NMWU4ffBqyYtbZ2U7mG/JxSMlt6DJBN0b/Xlw8eSENJVFqf7 HkZa/sDgJN3nPuQXT4uMfCnDeZBAn8mQyo9URxotjR3ByqZLQvI7ugzkkd3WII3m2w38 4zOXJCrn6J41HJt7Vpa6KMw4FrCiLAxMewELJMHLkIBwd3cMxNizQgPrR6SzL+f13nkn L8SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FkHJ1+Su; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si6451359edy.549.2021.10.14.19.35.35; Thu, 14 Oct 2021 19:35:58 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20210112 header.b=FkHJ1+Su; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232721AbhJNVFD (ORCPT + 99 others); Thu, 14 Oct 2021 17:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232171AbhJNVFC (ORCPT ); Thu, 14 Oct 2021 17:05:02 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7722FC061753 for ; Thu, 14 Oct 2021 14:02:57 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id y15so32518818lfk.7 for ; Thu, 14 Oct 2021 14:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jI0siKnxYryfR0Wrdx331NbLBs00Z1e/lOmM3iHWBvg=; b=FkHJ1+SuGsYHNEnajUrbdjmmenaWDJxK5uswFbuDCEAZAe+L70XBTKeyNh4LDkvWZ1 h2BmYh8hGU/POVpfrmDBuUc0KWG6gHaAx7iA55l7wCKaumVPrEhCbGWnI00rv3K2jkwH XhBcKWk8QVQmDRjijfarw0WgNaaJX65EjuZpkTGCVcSEQFYYPWMpPIPxcri8sD4iJpto GcH5SowKvbolFnGTF9RXRWLC8VsJVihgAT4p0tyLbubZqWO+WWk23HMhXgufamoaME5g x5HZl0oEesVm+x79xGRaQrjiXZObv3w2HJVFC5G89JUWDeXtgyGmQx31y9UeYo7R6Lhh EuSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jI0siKnxYryfR0Wrdx331NbLBs00Z1e/lOmM3iHWBvg=; b=R3/P/PJSZXO3uEm6u1GBaxkThzuZRn+J4FwGaHyMYwazXAljulxQeOjbpHzbxW5XnB ZaJ+RQRMg6cS5kdTT74FZ7iPUuSJ60YN0I7FN5V4X1PF4aMoEGTGSODU3SKqlSwl4dVZ W7BgBzNZHB6FxAWBjKRvYHTbyX/1Kb0/ioQ4cBcsnO9ymyUG+Ak21MZyIUfAHidsiuxY 6Qa/+LV9Rk+vukFfcxoOyaLiYh5P4sr0yrDh3kAiNqsGcq9h8qgtvw1hqYQGu4oSQoaq yzdgi1y1zTlEphsPEphL8B9EmMdYL3Ey1G/VP8I9uoUDSkH7XvmJJF2eOCpoEfWTRoOG 3fvA== X-Gm-Message-State: AOAM5339rzvZg8ETUBd05U4k+REXoRTYFfxk5tUkBMTj8Ju73rLbm5Rn eesL3k+xSzzZJzftS3gosFjIsQ6Q1qQmbMURWa3/qg== X-Received: by 2002:ac2:434c:: with SMTP id o12mr7092282lfl.82.1634245375477; Thu, 14 Oct 2021 14:02:55 -0700 (PDT) MIME-Version: 1.0 References: <20211014205757.3474635-1-nathan@kernel.org> In-Reply-To: <20211014205757.3474635-1-nathan@kernel.org> From: Nick Desaulniers Date: Thu, 14 Oct 2021 14:02:43 -0700 Message-ID: Subject: Re: [PATCH] Input: touchscreen - Avoid bitwise vs logical OR warning To: Nathan Chancellor Cc: Dmitry Torokhov , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 14, 2021 at 1:58 PM Nathan Chancellor wrote: > > A new warning in clang points out a few places in this driver where a > bitwise OR is being used with boolean types: > > drivers/input/touchscreen.c:81:17: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical] > data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x", > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > This use of a bitwise OR is intentional, as bitwise operations do not > short circuit, which allows all the calls to touchscreen_get_prop_u32() > to happen so that the last parameter is initialized while coalescing the > results of the calls to make a decision after they are all evaluated. > > To make this clearer to the compiler, use the '|=' operator to assign > the result of each touchscreen_get_prop_u32() call to data_present, > which keeps the meaning of the code the same but makes it obvious that > every one of these calls is expected to happen. > > Link: https://github.com/ClangBuiltLinux/linux/issues/1472 > Signed-off-by: Nathan Chancellor Thanks for the patch! Reported-by: Nick Desaulniers Reviewed-by: Nick Desaulniers > --- > drivers/input/touchscreen.c | 42 ++++++++++++++++++------------------- > 1 file changed, 21 insertions(+), 21 deletions(-) > > diff --git a/drivers/input/touchscreen.c b/drivers/input/touchscreen.c > index dd18cb917c4d..4620e20d0190 100644 > --- a/drivers/input/touchscreen.c > +++ b/drivers/input/touchscreen.c > @@ -80,27 +80,27 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch, > > data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x", > input_abs_get_min(input, axis_x), > - &minimum) | > - touchscreen_get_prop_u32(dev, "touchscreen-size-x", > - input_abs_get_max(input, > - axis_x) + 1, > - &maximum) | > - touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x", > - input_abs_get_fuzz(input, axis_x), > - &fuzz); > + &minimum); > + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-x", > + input_abs_get_max(input, > + axis_x) + 1, > + &maximum); > + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x", > + input_abs_get_fuzz(input, axis_x), > + &fuzz); > if (data_present) > touchscreen_set_params(input, axis_x, minimum, maximum - 1, fuzz); > > data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-y", > input_abs_get_min(input, axis_y), > - &minimum) | > - touchscreen_get_prop_u32(dev, "touchscreen-size-y", > - input_abs_get_max(input, > - axis_y) + 1, > - &maximum) | > - touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y", > - input_abs_get_fuzz(input, axis_y), > - &fuzz); > + &minimum); > + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-y", > + input_abs_get_max(input, > + axis_y) + 1, > + &maximum); > + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y", > + input_abs_get_fuzz(input, axis_y), > + &fuzz); > if (data_present) > touchscreen_set_params(input, axis_y, minimum, maximum - 1, fuzz); > > @@ -108,11 +108,11 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch, > data_present = touchscreen_get_prop_u32(dev, > "touchscreen-max-pressure", > input_abs_get_max(input, axis), > - &maximum) | > - touchscreen_get_prop_u32(dev, > - "touchscreen-fuzz-pressure", > - input_abs_get_fuzz(input, axis), > - &fuzz); > + &maximum); > + data_present |= touchscreen_get_prop_u32(dev, > + "touchscreen-fuzz-pressure", > + input_abs_get_fuzz(input, axis), > + &fuzz); > if (data_present) > touchscreen_set_params(input, axis, 0, maximum, fuzz); > > > base-commit: a41392e0877a271007e9209e63c34cab7527eb43 > -- > 2.33.1.637.gf443b226ca > > -- Thanks, ~Nick Desaulniers