Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp201487pxb; Thu, 12 Aug 2021 14:20:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFmQbBSB4M5QMpW5sD767jULsTH52OExxn3w8Y8fU4hIDixdJdgKwf7ChLP4i4R0Ts1f+1 X-Received: by 2002:a05:6402:3507:: with SMTP id b7mr8038566edd.293.1628803231434; Thu, 12 Aug 2021 14:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628803231; cv=none; d=google.com; s=arc-20160816; b=XsDrjm2EhRHRtnVNMeLQcDIobrqbcEiOaPAMN+rQ+mHsgYC85s/66wJuvHk/A3O5xe Ze/Ye3Wc/T+tBlNQsifyZJ+ouTKg7hQ8qlROpfU4G5+WLU8JhvaYnRLX9Mg19SFcZKGy CzaZ34GVkLZgNzd5gd1LX5U6eMSEt6wrd9IIZVdhHg7RKI/Tc8hVDy6Ia6Rw6N5Ah43C ROu5JvvC5njQEaExN3GDJI9h4l8Y1QXFxeAaLY+TrR/J4c8KiD3/GjK0t05ISRmAuYcw DQNUakSWopwM+7gBq0/ZkPcFeqqp9K5KkVH6TgprTC8GllV3ZiAaY2soFdPDUeq1yeJ3 aQ1g== 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=WyarTx/bV9rblC65snb3qvytdBQ7XGyyP0s6efBhIqA=; b=V2ojgxvV6bkKkaQ0qlOv3xm1Vs22ETKfJ+ZlDtKKoNhQWBH7cqclziQLNTLFutWumO WwsylwEEVvEjkLdhGZPkWL5J6maCOy6HZULPGB0urwTIbesn15nuKcwpH5nXk0yL6vbW KrscORNTSbeIV62NLZ9nb8I6HiSWjMgsYw0YAM0kxLuraUN1jt00t4wk2v6PP4Z/DZaF 93cdedVTFqNcQxqDJP0OfEqxkzU7GUWyoP1tuNDifGiO7x4solK0nqy3B1codo+PfjKJ DseelijqBiycV2fK4aJGypqONn/P+DnR62bk6GjZbUv6HzFULk5+66sRL3OzfBYsPRDE YQvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@philpotter-co-uk.20150623.gappssmtp.com header.s=20150623 header.b=rYySSj0V; 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 d15si3660578edt.431.2021.08.12.14.20.07; Thu, 12 Aug 2021 14:20:31 -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=@philpotter-co-uk.20150623.gappssmtp.com header.s=20150623 header.b=rYySSj0V; 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 S235530AbhHLVQg (ORCPT + 99 others); Thu, 12 Aug 2021 17:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234708AbhHLVQf (ORCPT ); Thu, 12 Aug 2021 17:16:35 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AFF3C061756 for ; Thu, 12 Aug 2021 14:16:10 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so17394232pjr.1 for ; Thu, 12 Aug 2021 14:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WyarTx/bV9rblC65snb3qvytdBQ7XGyyP0s6efBhIqA=; b=rYySSj0VwvwfzRfA2inQGsoF5d5tVMHmp3wsktT+vwPuUuEaJiIcektHIBKiXvot98 CJNM36xypN8Dmk1qwV77xlpIs3uoFFka1CM1/KdLt3mAb9Gl3nlanWtLtiMHciUHI6+2 0GDoEPNO7RWQj9AqoWjzq94TOqT4KLoEvHEjVSjuOJP5MrXg41lKnVMO/vc/GMKVBsUz Q2gbtNNMLVZ54kQAF5OwRwnP3bQWp0xzITlJXUDh4vHscUQ4b6OyxVaxRYJ8ijbeDL0b AB0s7Y/tubMc8rG/rr8l1tFXBisNucRK/JEzHHR8sM+jj8U66HI3iA3UeKDFXEcHyOtH iksg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WyarTx/bV9rblC65snb3qvytdBQ7XGyyP0s6efBhIqA=; b=rWb+zzpb+mDu7wiEF8AZLuniGnSP9/nSmFWPyWtIXILb/pgFlfuy1Bn6EVHFoHAe+P dZ3XOoktTgfLZfdQdyvOlRKFnLqnBefBnwP88HI8Dmx+o4sF0K43l+iTTYJPLt+SbRWT aaOWn9U0Z/ECvZGfqgnlsSk4uju0lttyv5P77WlpbCEp/ziYwyY8Opogb1ekW1hrpIxE 1b96oAVVppOTh0ggxbSCOo45Xn9NQBzLG7q6l0B0wWfLIGH/lfYVMVDfen/XUoAB8O6I np344gthRZ61Wc7OfXT/uK6cGWtUCyzeWi3GmLieJ+qMsoCSCLfCBpKH2hifMqEQKJuO 4W+A== X-Gm-Message-State: AOAM53277kQ+pj+BSIWONV9b77Gu9A4KhqLxFV7W8NI9IUw+SjQ3/MuQ Vym9MtjGgDriFpfyMAHhHs/R8yCnoFVrutjL0YUsIg== X-Received: by 2002:a63:aa43:: with SMTP id x3mr5645795pgo.208.1628802969580; Thu, 12 Aug 2021 14:16:09 -0700 (PDT) MIME-Version: 1.0 References: <20210812204027.338872-1-nathan@kernel.org> <20210812204027.338872-4-nathan@kernel.org> In-Reply-To: <20210812204027.338872-4-nathan@kernel.org> From: Phillip Potter Date: Thu, 12 Aug 2021 22:15:58 +0100 Message-ID: Subject: Re: [PATCH 3/3] staging: r8188eu: Reorganize error handling in rtw_drv_init() To: Nathan Chancellor Cc: Greg Kroah-Hartman , Larry Finger , Nick Desaulniers , linux-staging@lists.linux.dev, Linux Kernel Mailing List , clang-built-linux@googlegroups.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 12 Aug 2021 at 21:40, Nathan Chancellor wrote: > > After commit 987219ad34a6 ("staging: r8188eu: remove lines from Makefile > that silence build warnings"), clang warns: > > drivers/staging/r8188eu/os_dep/usb_intf.c:726:6: warning: variable > 'status' is used uninitialized whenever 'if' condition is true > [-Wsometimes-uninitialized] > if (!if1) { > ^~~~ > drivers/staging/r8188eu/os_dep/usb_intf.c:741:6: note: uninitialized use > occurs here > if (status != _SUCCESS) > ^~~~~~ > drivers/staging/r8188eu/os_dep/usb_intf.c:726:2: note: remove the 'if' > if its condition is always false > if (!if1) { > ^~~~~~~~~~~ > drivers/staging/r8188eu/os_dep/usb_intf.c:714:12: note: initialize the > variable 'status' to silence this warning > int status; > ^ > = 0 > 1 warning generated. > > status is not initialized if the call to usb_dvobj_init() or > rtw_usb_if1_init() fails. > > Looking at the error function as a whole, the error handling is odd > compared to the rest of the kernel, which prefers to set error codes on > goto paths, rather than a global "status" variable which determines the > error code at the end of the function and function calls in the case of > error. > > Rearrange the error handling of this function to bring it more inline > with how the kernel does it in most cases, which helps readability. > > The call to rtw_usb_if1_deinit() is eliminated because it is not > possible to ever hit it; if rtw_usb_if1_init() fails, the goto call > jumps over the call to rtw_usb_if1_deinit() and in the success case, > status is set to _SUCCESS. > > Signed-off-by: Nathan Chancellor > --- > drivers/staging/r8188eu/os_dep/usb_intf.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c > index a462cb6f3005..667f41125a87 100644 > --- a/drivers/staging/r8188eu/os_dep/usb_intf.c > +++ b/drivers/staging/r8188eu/os_dep/usb_intf.c > @@ -704,20 +704,23 @@ static void rtw_usb_if1_deinit(struct adapter *if1) > static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid) > { > struct adapter *if1 = NULL; > - int status; > struct dvobj_priv *dvobj; > + int ret; > > /* step 0. */ > process_spec_devid(pdid); > > /* Initialize dvobj_priv */ > dvobj = usb_dvobj_init(pusb_intf); > - if (!dvobj) > - goto exit; > + if (!dvobj) { > + ret = -ENODEV; > + goto err; > + } > > if1 = rtw_usb_if1_init(dvobj, pusb_intf); > if (!if1) { > DBG_88E("rtw_init_primarystruct adapter Failed!\n"); > + ret = -ENODEV; > goto free_dvobj; > } > > @@ -726,15 +729,12 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device > rtw_signal_process(ui_pid[1], SIGUSR2); > } > > - status = _SUCCESS; > + return 0; > > - if (status != _SUCCESS && if1) > - rtw_usb_if1_deinit(if1); > free_dvobj: > - if (status != _SUCCESS) > - usb_dvobj_deinit(pusb_intf); > -exit: > - return status == _SUCCESS ? 0 : -ENODEV; > + usb_dvobj_deinit(pusb_intf); > +err: > + return ret; > } > > /* > -- > 2.33.0.rc2 > Looks good as far as I can see, nicely done. Thanks. Acked-by: Phillip Potter Regards, Phil