From patchwork Sat Dec 10 09:01:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 31993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1213327wrr; Sat, 10 Dec 2022 01:13:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf79d3VBT3IJJZ0oWagNNbfIt3MVg6ySaz0xxBVxzXOM5RfxuZEbKyoU0aN/wiubwwblVLEg X-Received: by 2002:a05:6a20:bb01:b0:aa:8086:4af9 with SMTP id fc1-20020a056a20bb0100b000aa80864af9mr11955421pzb.20.1670663598940; Sat, 10 Dec 2022 01:13:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670663598; cv=none; d=google.com; s=arc-20160816; b=zUwDSkr8hVzdV3JWd0AJpxgR/6VTBu9DPmpH7e+5qr7+ZJ8l8hd18SFa3oEZHLYU7Q j0UouSE49m24SYEqzz4dVLkHVONjBVch/MX1ExQihzvkkuW+8oFb8ORMQg76VT1KjSsA WPM8TwjpO0MiLHRhTuG+NL3Ley6VcG4zu1DuDfGH50bnS9eyJ5VQQAe/0sSgtBumdxdj AFneUQTOqWXdlpeeO5fCP5MleKJk2+pSu7+fMC/xmgJ+VmbxyFQU7qCFbnqkdQdz9MWk 1NuIL3EazMRQ0r5aMuT1HEhgD1lahy/I9bxKDS86NrdXgQHDoBSjLXTCDP+gInw/x60c EloQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=+JLuq6z6RC38yxJgv0nky22X6DCSZ/hpLwA+DNaYB3g=; b=BffihS8kwArqORXk7XgOVyz1J73yyAa/mODj5CHk0IOL3N6vBwv7VJq+kK7ybWEPEf aUyjoljEZu2A5kbUhZf4sT3wPmc3ndP7yTSUMlOt1N3gULTWkDRq3VCF+mh19lTeeCkl axWD8Boxu9vIguDav4qD/Am9QO7/kg8BRjMBDuVkwNzBMCoW+n9YAErk4q376wXk0TFL F94t+LwOYTJGjQE/vSYdlDZjbbu8MaGabeYa1TLqDy63AWddx1n2U5X0Rggr1VLEEIi8 zi/KzMtYbHSg6ZRU2gzVbiLrCgKv8UFhcLXZU9v7QFcpQ4yW/kxQ8q8paDWb7aVN0kdD Katg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pYzKZaA9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x71-20020a63864a000000b004792b08adabsi1689404pgd.750.2022.12.10.01.13.05; Sat, 10 Dec 2022 01:13:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pYzKZaA9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbiLJJGW (ORCPT + 99 others); Sat, 10 Dec 2022 04:06:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbiLJJFM (ORCPT ); Sat, 10 Dec 2022 04:05:12 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C09275D5; Sat, 10 Dec 2022 01:03:46 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id 3-20020a17090a098300b00219041dcbe9so7382602pjo.3; Sat, 10 Dec 2022 01:03:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+JLuq6z6RC38yxJgv0nky22X6DCSZ/hpLwA+DNaYB3g=; b=pYzKZaA9CAYA1lV0aFDqGItcg2wPbv7kFZNxnILtD51hI2Z0Slg+qdAQ8nV1HCcfSA 3p3xy/O3vBdiRfLdB+vj6Ksz9HnYQ4tndul1j1Kus7zt80bmzNr2C2YLRX/tZvXrfkDt qUaV1cJq+DcbxSf1zI+/q5Joe+oQ87GTDXGlZFhO1vrjILUOHuORDxcE7IAswjElSI7d le6Fl9k5YU3CJ3i6FnIn4RsAlFopeglX3XGEIIIgRNTu5/mqb+gTpi6IRJUwzMzelCed facKMtOZwVa5+ygm2R2ua7ITJc3cKCdpWfxXJjFE0bq10g5KfSv9/5tMS9zsdbeoRnTO 3EGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+JLuq6z6RC38yxJgv0nky22X6DCSZ/hpLwA+DNaYB3g=; b=Jh5Ic65uP4swDCyt6PC9bIF7UZf2cFCQjEseRPnM7Dh9beoDzT1r3qeC+vzUAgK4/L GLyQFJR1jFB+Rvq31F3rP2PXGyq+K6cTWufqqwUOwS+UT109Zuuh8kKC4kc8tQ+KUzGL oSfMelFoMMkUIlP5di3jqfK8vQ+CNCf31oUFLWzAmYzP9XLA+eS+uLdWe9nc1aC6jXEb S2zyZhQ8eZyaGqblDHkeSr3fIcnkEYdOszQw44/yftxPZrH4YbtfMXDPhM0V0G3tyJs4 ckCrdx7FpjCnARLyifpVq52V720U9Ra4xRbnEt++Eom2qFmdK3J/jh14ItpKYqIjh7je apLQ== X-Gm-Message-State: ANoB5plmAfaVw6oOYflOr4cDVW8RaGcdbtWal+2dtppzUhCTwr7Etjth 3vghoyYwpxGDFAYZkM2vGO4= X-Received: by 2002:a17:903:120b:b0:188:eec0:f1e with SMTP id l11-20020a170903120b00b00188eec00f1emr11952017plh.63.1670663025813; Sat, 10 Dec 2022 01:03:45 -0800 (PST) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id u7-20020a17090282c700b00186a2444a43sm2549481plz.27.2022.12.10.01.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Dec 2022 01:03:45 -0800 (PST) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: Oliver Neukum , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank Jungclaus , socketcan@esd.eu, Yasushi SHOJI , =?utf-8?q?Stefan_M=C3=A4tje?= , Hangyu Hua , Oliver Hartkopp , Peter Fink , Jeroen Hofstee , =?utf-8?q?Christoph_M=C3=B6hring?= , John Whittington , Vasanth Sadhasivan , Jimmy Assarsson , Anssi Hannula , Pavel Skripkin , Stephane Grosjean , Wolfram Sang , "Gustavo A . R . Silva" , Julia Lawall , Dongliang Mu , Sebastian Haas , Maximilian Schneider , Daniel Berglund , Olivier Sobrie , =?utf-8?b?UmVtaWdpdXN6IEtvxYLFgsSFdGFq?= , Jakob Unterwurzacher , Martin Elshuber , Bernd Krumboeck , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alan Stern , linux-usb@vger.kernel.org, Vincent Mailhol Subject: [PATCH v2 8/9] can: usb: remove useless check on driver data Date: Sat, 10 Dec 2022 18:01:56 +0900 Message-Id: <20221210090157.793547-9-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221210090157.793547-1-mailhol.vincent@wanadoo.fr> References: <20221203133159.94414-1-mailhol.vincent@wanadoo.fr> <20221210090157.793547-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751817753971643753?= X-GMAIL-MSGID: =?utf-8?q?1751817753971643753?= Many of the can usb drivers checks in their usb_driver::disconnect() whether the driver data is NULL or not. This check only makes sense if the disconnect function can be called more than one time. This is not the case for can usb drivers. Remove all checks toward drivers priv data in disconnect(). Signed-off-by: Vincent Mailhol --- drivers/net/can/usb/ems_usb.c | 14 ++++++-------- drivers/net/can/usb/esd_usb.c | 16 +++++++--------- drivers/net/can/usb/gs_usb.c | 5 ----- drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 7 +------ drivers/net/can/usb/ucan.c | 6 ++---- drivers/net/can/usb/usb_8dev.c | 11 ++++------- 6 files changed, 20 insertions(+), 39 deletions(-) diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c index c64cb40ac8de..8bd555eb741f 100644 --- a/drivers/net/can/usb/ems_usb.c +++ b/drivers/net/can/usb/ems_usb.c @@ -1062,18 +1062,16 @@ static void ems_usb_disconnect(struct usb_interface *intf) { struct ems_usb *dev = usb_get_intfdata(intf); - if (dev) { - unregister_netdev(dev->netdev); + unregister_netdev(dev->netdev); - unlink_all_urbs(dev); + unlink_all_urbs(dev); - usb_free_urb(dev->intr_urb); + usb_free_urb(dev->intr_urb); - kfree(dev->intr_in_buffer); - kfree(dev->tx_msg_buffer); + kfree(dev->intr_in_buffer); + kfree(dev->tx_msg_buffer); - free_candev(dev->netdev); - } + free_candev(dev->netdev); } /* usb specific object needed to register this driver with the usb subsystem */ diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c index f3006c6dc5d6..775ab704a295 100644 --- a/drivers/net/can/usb/esd_usb.c +++ b/drivers/net/can/usb/esd_usb.c @@ -1127,17 +1127,15 @@ static void esd_usb_disconnect(struct usb_interface *intf) device_remove_file(&intf->dev, &dev_attr_hardware); device_remove_file(&intf->dev, &dev_attr_nets); - if (dev) { - for (i = 0; i < dev->net_count; i++) { - if (dev->nets[i]) { - netdev = dev->nets[i]->netdev; - unregister_netdev(netdev); - free_candev(netdev); - } + for (i = 0; i < dev->net_count; i++) { + if (dev->nets[i]) { + netdev = dev->nets[i]->netdev; + unregister_netdev(netdev); + free_candev(netdev); } - unlink_all_urbs(dev); - kfree(dev); } + unlink_all_urbs(dev); + kfree(dev); } /* usb specific object needed to register this driver with the usb subsystem */ diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index 97b1da8fd19f..40190816e313 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -1458,11 +1458,6 @@ static void gs_usb_disconnect(struct usb_interface *intf) struct gs_usb *dev = usb_get_intfdata(intf); unsigned int i; - if (!dev) { - dev_err(&intf->dev, "Disconnect (nodata)\n"); - return; - } - for (i = 0; i < GS_MAX_INTF; i++) if (dev->canch[i]) gs_destroy_candev(dev->canch[i]); diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c index dad916b3288e..9e83b61db96b 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c @@ -979,12 +979,7 @@ static int kvaser_usb_probe(struct usb_interface *intf, static void kvaser_usb_disconnect(struct usb_interface *intf) { - struct kvaser_usb *dev = usb_get_intfdata(intf); - - if (!dev) - return; - - kvaser_usb_remove_interfaces(dev); + kvaser_usb_remove_interfaces(usb_get_intfdata(intf)); } static struct usb_driver kvaser_usb_driver = { diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c index 429b3519ee7f..205941122f9e 100644 --- a/drivers/net/can/usb/ucan.c +++ b/drivers/net/can/usb/ucan.c @@ -1579,10 +1579,8 @@ static void ucan_disconnect(struct usb_interface *intf) { struct ucan_priv *up = usb_get_intfdata(intf); - if (up) { - unregister_candev(up->netdev); - free_candev(up->netdev); - } + unregister_candev(up->netdev); + free_candev(up->netdev); } static struct usb_device_id ucan_table[] = { diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c index ae618809fc05..4d80049ebff7 100644 --- a/drivers/net/can/usb/usb_8dev.c +++ b/drivers/net/can/usb/usb_8dev.c @@ -990,14 +990,11 @@ static void usb_8dev_disconnect(struct usb_interface *intf) { struct usb_8dev_priv *priv = usb_get_intfdata(intf); - if (priv) { - netdev_info(priv->netdev, "device disconnected\n"); - - unregister_netdev(priv->netdev); - unlink_all_urbs(priv); - free_candev(priv->netdev); - } + netdev_info(priv->netdev, "device disconnected\n"); + unregister_netdev(priv->netdev); + unlink_all_urbs(priv); + free_candev(priv->netdev); } static struct usb_driver usb_8dev_driver = {