Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2630540rdg; Mon, 16 Oct 2023 09:53:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWCedg8EEQD0OP+kPbsHKaBHnTozptDsrY7RVrD4gyTOkDmZTOzv/gCVZGxB0+ccfDJ8Bf X-Received: by 2002:a05:6a20:1387:b0:174:30e:43a1 with SMTP id hn7-20020a056a20138700b00174030e43a1mr13644577pzc.3.1697475238811; Mon, 16 Oct 2023 09:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697475238; cv=none; d=google.com; s=arc-20160816; b=aR9BNFQ5A4T572C8O4QOWiGDpTBfYPLyJ58aGAi6XtkoxcyxSQh1E9GTS4/6As42cn mcysyEntxL66yigoFpCln8NZGgUiIk5QPF7AN0pDkeCO2Oxeyh+Q9hfmPyjDjJliZ8kO 5aAyU/+sBFheCZPmbRuVuFY0V6E3rnGjObqoQV2ben04NVJDkBTgb6uXI+ZrCeBlPF24 hDp9/xQ9E9RmeJGFvBI3Jx14OSxPGgWiuCu51FzLapKLxoFtsQk3rROQql022o87ICQA dqVbtqAkuWxgTpoagwCkBlzSpboCqmndQPcGuOm7H80PXMX98pTBGLt7JRLA7r1GUHPV YCNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+ZJGLg3D+ucnPrjgrPwyMGRdiSy2W8deAmYMGodOcfI=; fh=iJsalaXmidhURGX008f+DSnCgo0h3/hKS/XEp3qYuBA=; b=UU4bS3hcA1n0p8tJax2Aktr2Y3UFwT19C1iQrOhysP/RHf38vau5Eh6yknIYZSUcDp Ts1K4pqyCECO2WAZLV7zl4SNn6rZkkdTPEY3GuOXXLEbKpFzTAgCYqqYJZSSiqMRRUxN ukov1+CKEqWfJGCk8neczjKEnPpyflXG15OY3Bw8e2GtPAkQKDD1JAsHY8MQizQlX9UL S+n0OQtUyquOK79D2LrZT0tekq4lAbuZ8PRBDwLplC3cBtlyKcFCAvqfo6CH5B293SMt J5+hK0haVKvDei4PQht/BO8wJa62ka5H5rV2eP45pzAHJBAu/Chk6DtmwM73SmrQybin uI9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NEgBRQba; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x8-20020a63db48000000b005898e10f9cbsi11131214pgi.572.2023.10.16.09.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:53:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NEgBRQba; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1A8DE8040C69; Mon, 16 Oct 2023 09:53:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233959AbjJPQxs (ORCPT + 99 others); Mon, 16 Oct 2023 12:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233901AbjJPQxf (ORCPT ); Mon, 16 Oct 2023 12:53:35 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1E1B19B7 for ; Mon, 16 Oct 2023 09:47:01 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9adca291f99so741966766b.2 for ; Mon, 16 Oct 2023 09:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697474818; x=1698079618; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+ZJGLg3D+ucnPrjgrPwyMGRdiSy2W8deAmYMGodOcfI=; b=NEgBRQbaelu7WBM/f6gS6aelPx9qGiijcDF9QrAsaEcxd2nbDBPfkt6SRE15soiIkj 4lhnUUzbiQgr0ob70QDPjZEBMrV3IZssUtc554leeWxAglo687E41tJBtrgFf0eYNPFY IK351SzBgEJt4xIzj7mH/ob47iiM+1TOrWs04= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697474818; x=1698079618; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+ZJGLg3D+ucnPrjgrPwyMGRdiSy2W8deAmYMGodOcfI=; b=wC9sPlwGGka3lrnB6h5uxTMjRpNEA6Jra6hOR3J1Eux7uKY+fyNHAu41DF2RwgpjHz w/xCli+QKdY5UG6E+Wsh8sdUp/3neuFcMlWl2paupAP4/PIKYxfCKxDO0y82Y8cKiyZy /QWfb64gU7Pb8BTVWoNNBZGbBWnz1sLtBhT7FkfEKZ3xo2AbedwWvGO5hNnXzgItx0Q9 L0b2IDvA1XKWXFtrP6QRED201HhNSUl/m9IdALGHAYJYuU2419xoDiqaAU4UjBXMRIFz VFsWdr3WnUcDguh48F0OpmagP1w5sCQR2g2iiYS9sCsA/L+U4g2pBk/TRLEqVyBbFksx vX3A== X-Gm-Message-State: AOJu0YzvTz5Quz8zizE1Ick4bsmDKNnnsbThQDw46hsdqw5rqmHYFMG+ 2tIAc11+RDzI4r0X3X95yKbZZhRkn7R53UWw6Np64A== X-Received: by 2002:a17:907:1c26:b0:9bf:5df1:38cc with SMTP id nc38-20020a1709071c2600b009bf5df138ccmr5436267ejc.4.1697474818245; Mon, 16 Oct 2023 09:46:58 -0700 (PDT) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com. [209.85.128.49]) by smtp.gmail.com with ESMTPSA id u20-20020a170906c41400b009b9720a85e5sm4366744ejz.38.2023.10.16.09.46.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Oct 2023 09:46:57 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4053f24c900so1145e9.1 for ; Mon, 16 Oct 2023 09:46:57 -0700 (PDT) X-Received: by 2002:a05:600c:3c83:b0:405:38d1:e146 with SMTP id bg3-20020a05600c3c8300b0040538d1e146mr211926wmb.4.1697474816851; Mon, 16 Oct 2023 09:46:56 -0700 (PDT) MIME-Version: 1.0 References: <20231012192552.3900360-1-dianders@chromium.org> <20231012122458.v3.5.Ib2affdbfdc2527aaeef9b46d4f23f7c04147faeb@changeid> <29f9a2ff1979406489213909b940184f@realtek.com> In-Reply-To: <29f9a2ff1979406489213909b940184f@realtek.com> From: Doug Anderson Date: Mon, 16 Oct 2023 09:46:39 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 5/5] r8152: Block future register access if register access fails To: Hayes Wang Cc: Jakub Kicinski , "David S . Miller" , Alan Stern , Simon Horman , Edward Hill , Laura Nao , "linux-usb@vger.kernel.org" , Grant Grundler , =?UTF-8?Q?Bj=C3=B8rn_Mork?= , Eric Dumazet , Paolo Abeni , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:53:56 -0700 (PDT) Hi, On Mon, Oct 16, 2023 at 2:16=E2=80=AFAM Hayes Wang = wrote: > > Douglas Anderson > > Sent: Friday, October 13, 2023 3:25 AM > [...] > > static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, > > @@ -8265,6 +8353,19 @@ static int rtl8152_pre_reset(struct usb_interfac= e > > *intf) > > if (!tp) > > return 0; > > > > + /* We can only use the optimized reset if we made it to the end= of > > + * probe without any register access fails, which sets > > + * `PROBED_WITH_NO_ERRORS` to true. If we didn't have that then= return > > + * an error here which tells the USB framework to fully unbind/= rebind > > + * our driver. > > Would you stay in a loop of unbind and rebind, > if the control transfers in the probe() are not always successful? > I just think about the worst case that at least one control always fails = in probe(). We won't! :-) One of the first things that rtl8152_probe() does is to call rtl8152_get_version(). That goes through to rtl8152_get_version(). That function _doesn't_ queue up a reset if there are communication problems, but it does do 3 retries of the read. So if all 3 reads fail then we will permanently fail probe, which I think is the correct thing to do. I can update the comment in __rtl_get_hw_ver() to make it more obvious that this is by design? > > > + */ > > + mutex_lock(&tp->control); > > I don't think you need the mutex for testing the bit. Sure, I'll remove it. > > + if (!test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) { > > + mutex_unlock(&tp->control); > > + return -EIO; > > + } > > + mutex_unlock(&tp->control); > > + > > netdev =3D tp->netdev; > > if (!netif_running(netdev)) > > return 0; > > @@ -8277,7 +8378,9 @@ static int rtl8152_pre_reset(struct usb_interface > > *intf) > > napi_disable(&tp->napi); > > if (netif_carrier_ok(netdev)) { > > mutex_lock(&tp->control); > > + set_bit(IN_PRE_RESET, &tp->flags); > > tp->rtl_ops.disable(tp); > > + clear_bit(IN_PRE_RESET, &tp->flags); > > mutex_unlock(&tp->control); > > } > > > > @@ -8293,6 +8396,10 @@ static int rtl8152_post_reset(struct usb_interfa= ce > > *intf) > > if (!tp) > > return 0; > > > > + mutex_lock(&tp->control); > > I don't think clear_bit() needs the protection of mutex. > I think you could call rtl_set_accessible() directly. Agreed, I'll take this out. Unless something else comes up, I'll send a new version tomorrow with the above small changes. -Doug