Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755446AbdIGOQM (ORCPT ); Thu, 7 Sep 2017 10:16:12 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:62609 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754964AbdIGOQK (ORCPT ); Thu, 7 Sep 2017 10:16:10 -0400 From: Arnd Bergmann To: Felipe Balbi , Greg Kroah-Hartman Cc: Arnd Bergmann , Tatyana Brokhman , Alan Stern , Peter Chen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] usb: gadget: dummy: fix nonsensical comparisons Date: Thu, 7 Sep 2017 16:14:31 +0200 Message-Id: <20170907141559.3739432-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:tLPRKST7Dr+nHIkbaE5790SBCyMtif0p1ZqjQrj8ki+rXbs0TKA NvPXld4WJdYUfjzu4UWQKLMrr25fhtMUyAxDvciZ1wryVxH2xfOrze61p8RdPj3jBZi05T5 NiWEi4+3oGBJVGQz+W/SrKoGfWw6MwG5FYjix10VjchNlWpUoOoCh+rimyb0u+sk7dnXtbo RnjdCDHCiZVXUiwoP9VeQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:uZNd3QouxH8=:wDfQ+vcPdje/T2Hk0gz94G KRm1oZPU0LQUycnGNE9du+Rs/slogDyddbg4tMBO70163YsetU+smDv1uI2R1wWMkU/nP8Crj Zn+2Hj2udyIcPfdCiSSjB+VZ75+BlYBEfut2tyFsRwj1HDbggqLdw8DJFjamsoj+nR6uLV9vx eVCdwnDlCTSCcro0LbE541MiravqyWRv0Q0k58N6eUWzhRxZU3OTNDW7qhKd0RCG7u561MFXK Y2oE5f2MdROKBGLoNWAHEwRpEJLIgVpMviRBwX+/wyjEDpaIOxWRkhJ2War0/d8UR0vaAudIO pRbG6i5XOqMp0XxiAWmpNHX29C9Jb5Jso5POwf8A7piIW2eUj+w6Sm69EMkxcto0pj5Qh6oDN 9koh6OPNgzj8VBX8smESazINo/hzX8FeMTxXphI1bQu/TJTgYO/4beffE6UFxAriMJMq3SSiM PgDIleXBw0OIneaZJS1ZKuLShSJT4D97V/fpcypwWP4uH25uCtrpO+MMnE9xxq4N8uZaNvAKb RmApeZKdxtM4FhimFW4k7PTozITjW5kx4CXNBis6Jl4LSbaIX5+txpbYYGFMJvTxMccq1Im4p B8go1IetMK9poXKNhLss9rlhA2Oh26xrIZVFRgxQRwCYo0IgsLfatJVi0UPpEvhUlFpNq+7st vr+YCSWP9/4RjxYglOyE+X/P6eDXDljIV/LfSw5s41nkemVLZ6DTZmyOK+gzKN6vcqMVlJHWw CX7hINAUPBE3RkLY+kvNVqjGntZUV1EuJSU4OA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2231 Lines: 52 gcc-8 points out two comparisons that are clearly bogus and almost certainly not what the author intended to write: drivers/usb/gadget/udc/dummy_hcd.c: In function 'set_link_state_by_speed': drivers/usb/gadget/udc/dummy_hcd.c:379:31: error: bitwise comparison always evaluates to false [-Werror=tautological-compare] USB_PORT_STAT_ENABLE) == 1 && ^~ drivers/usb/gadget/udc/dummy_hcd.c:381:25: error: bitwise comparison always evaluates to false [-Werror=tautological-compare] USB_SS_PORT_LS_U0) == 1 && ^~ I looked at the code for a bit and came up with a change that makes it look like what the author probably meant here. This makes it look reasonable to me and to gcc, shutting up the warning. It does of course change behavior as the two conditions are actually evaluated rather than being hardcoded to false, and I have made no attempt at verifying that the changed logic makes sense in the context of a USB HCD, so that part needs to be reviewed carefully. Fixes: 1cd8fd2887e1 ("usb: gadget: dummy_hcd: add SuperSpeed support") Cc: Tatyana Brokhman Cc: Felipe Balbi Signed-off-by: Arnd Bergmann --- v2: simplify the expression as suggested by Alan Stern --- drivers/usb/gadget/udc/dummy_hcd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index a030d7923d7d..b1e21b3be6e1 100644 --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c @@ -375,11 +375,10 @@ static void set_link_state_by_speed(struct dummy_hcd *dum_hcd) USB_PORT_STAT_CONNECTION) == 0) dum_hcd->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); - if ((dum_hcd->port_status & - USB_PORT_STAT_ENABLE) == 1 && - (dum_hcd->port_status & - USB_SS_PORT_LS_U0) == 1 && - dum_hcd->rh_state != DUMMY_RH_SUSPENDED) + if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) && + (dum_hcd->port_status & + USB_PORT_STAT_LINK_STATE) == USB_SS_PORT_LS_U0 && + dum_hcd->rh_state != DUMMY_RH_SUSPENDED) dum_hcd->active = 1; } } else { -- 2.9.0