From patchwork Tue Jun 7 09:47:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2018 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 1E7643F08A for ; Tue, 7 Jun 2022 11:48:21 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id c7-20020adfa707000000b002184d715e69sf662154wrd.10 for ; Tue, 07 Jun 2022 02:48:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654595301; cv=pass; d=google.com; s=arc-20160816; b=bo0WK5CcA5fMzI0i956obH2Jro0OVZyM6eexf6hvjLBMJo71pvnySLfozqS2+oQt3J Tm8ErKurlh9Z6gn1ntdLO8j6/JikIHXWv/Pk7Cn2gPLmHDwdzNpYtWagWLqyNLN+xfhk VQeVmFNDaIwfcAIHj5RKGe2f9NMMTY7rkNYWqrIIVazLZZG+NelY2gsSWMzkg11YOt8f PvsyW+c1Lw8gYg+QLBf8FW7ktVWzaa5L1ufRDhomWSqHbYYoHGTr44YSzRdubLi3acfw h//l9aHFcDZwag4ZFCl8MqxE1D3AfHgHLFTY3Qt5oBB7RfDIP7jSsL7IZoqIlrXgA3Ec uMpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=78U3DragEiB6xQxI4mgX6XIi14CGHnMLtY3yLj8Ln+0=; b=DK3UgkjzRt5CDksqJ2rTI11QuA/uakneg2+3XdflcSoPVFbtV+n5N4lKuHTZTzRCF4 M0P7G2JgY1fWt8GJNrhGo2y3qc6ZZj6WvzhEm4h/tGWHtWAZwEJA8ctdAsGQLsgxxgTJ xfvlkEGXfejjHdU0cSm5n+I0WMTo5ByUXghL4k/Y8LR7BJk659qgZ4G3OwU+9p1Wldvx mc5xGlt/LljC7UMUL+FSA4+4BYf8nAPBimEXm7cJUn1SUrLEfJYY3JNftE6dLJbFuxPy MpXWe+XZ5ZdN87d2N6TPfJb5vQgke3xynsWvC+1KruY6IGwT8E2AKtlgwatMpSDBg/PG WRPA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Iqu6UNp7; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=78U3DragEiB6xQxI4mgX6XIi14CGHnMLtY3yLj8Ln+0=; b=BXn7c/oQcEoIiv6TfqrD6asvN2FWEe+o6XA/ScLQ80PnjkIQmWR9Y0oH1DI3+Wlv1S c4TYW6/IKN+mrlL8Qfn6hjsE1K2xOwlOvIcqLIUyiHoicqFrk8KOUt+kaWOJta4JJBwv 55dZZ11KgFfuKZLuM83SJYBi9WgV3jUfoud0k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=78U3DragEiB6xQxI4mgX6XIi14CGHnMLtY3yLj8Ln+0=; b=XkW1TyavqEmZj71WhHR+p5AFvmDbl3KjOWFgNDHJ74pKaLpsT2/9dUeM+to0q39pzJ RJLpxKN5I9SxbcewLmQ0CAw/QUfEJoNMtHZQdU7jWOIncqfVJdYswUubcWU26fdg21Uh pzSw90mKB7f7zIvP5KkcHJpPyZUFwSZwzzDrFW1vQI40tP8OotUVKHW9klyrukQldYSt Hm7tBUbxeb3N0M5ObQvHUzyQcj5jhsKNzTZH66Ef8RrnSSRyVIjzzbEXkIthhFSNCY/S 3GAFdYYz4kywmG0HmWS9unIRwAkySPExZI7pnXHJQkSV9fELo4+JHWgRan95RUjcobZJ LAlA== X-Gm-Message-State: AOAM533qM/2CQtk0n7RkaKmqIb3SlNdUnvit1zQYg0boLfwJ0istR5er t+RFNnZxG2CdhsDWqvYE3uV9pGyP X-Google-Smtp-Source: ABdhPJwnCaXMtl5fxDrJ3aoimjXAPO/K1CC2dfURg0Z2AhnjoqBowYmo5U9p6nYuBhSzSwSzminUoA== X-Received: by 2002:a7b:c1c1:0:b0:39c:58c4:c701 with SMTP id a1-20020a7bc1c1000000b0039c58c4c701mr3352412wmj.117.1654595300844; Tue, 07 Jun 2022 02:48:20 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:648e:0:b0:217:c8b4:52e3 with SMTP id o14-20020a5d648e000000b00217c8b452e3ls4145020wri.1.gmail; Tue, 07 Jun 2022 02:48:19 -0700 (PDT) X-Received: by 2002:adf:e347:0:b0:217:6f4b:f3d6 with SMTP id n7-20020adfe347000000b002176f4bf3d6mr12942461wrj.73.1654595299692; Tue, 07 Jun 2022 02:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654595299; cv=none; d=google.com; s=arc-20160816; b=jnPX5w7AbkeynqSiGhh6+eOXwlIJeqo73W2PfVn84n9HWrDwzUfRIiwSf4x6ts+5It DdoFgnWLp9Qu8vwupDlY5fK/MRXEImcpFSxg+v0id2teXKca6sqOy60YvoA7c+BzLPPB OENj+1J8QOkkwzQMU5yyg2SpmXUGudNVQXcIzaaqZ9qm04vjluRKo5Q6kYyVnJ5EhJm4 Xz/mzXDnoBqui3+yQohsp/sNPhrgAwjc2xkjQ3AeNZRtHCc5IEOQvYA1HUvnAeB8rnOO RjEYdLiJ6kOG9KxDHO5Lbd9e4qw7PcvExS66NZJShOQ5ffs8YXX0YET8PDV3gb4EBZb2 Lxgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=flkxolnPRJ/fuZI8sau+S8LRxDQCGOpfvcgrJTeckZE=; b=mODbelgKbV2jaA3CELA90DGpWSE2AAFrKwmUxkLwVZzQ5wxmOOP4vVn8jEJjyUYeto 0Jgc5MlaG8+PtK8UCUvaI1j3wNUQ9ZOGg5In1Tb/r+gR2TLSH+KyxWcWV3lH6I7X7enN MgSWcIsACTdp0DtjAHdoIpzLyCLCW2QRJ+CuBCzLWegI0/ftjVXflLTYpYVu9k5p0kR+ /+AralXhJF51cohFv6AIdnqikgXrkhsD5znn2hGfrn1Hwhe2pBF+5GRartj7agCgBQIy byIy0UuryqBvy54iug8vwsp0pFyMttu4xPA0eO3c3/r8PLjww16ZLJXMFHJ+hntHGCyv UtKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Iqu6UNp7; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id v13-20020a056000144d00b00210133f6cafsor10241905wrx.74.2022.06.07.02.48.19 for (Google Transport Security); Tue, 07 Jun 2022 02:48:19 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a05:6000:186b:b0:20f:e2e5:f95f with SMTP id d11-20020a056000186b00b0020fe2e5f95fmr27169097wri.76.1654595299453; Tue, 07 Jun 2022 02:48:19 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (mob-5-90-137-51.net.vodafone.it. [5.90.137.51]) by smtp.gmail.com with ESMTPSA id o4-20020a05600c510400b0039748be12dbsm23200547wms.47.2022.06.07.02.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 02:48:18 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [RFC PATCH 05/13] can: slcan: simplify the device de-allocation Date: Tue, 7 Jun 2022 11:47:44 +0200 Message-Id: <20220607094752.1029295-6-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607094752.1029295-1-dario.binacchi@amarulasolutions.com> References: <20220607094752.1029295-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Iqu6UNp7; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Since slcan_devs array contains the addresses of the created devices, I think it is more natural to use its address to remove it from the list. It is not necessary to store the index of the array that points to the device in the driver's private data. Signed-off-by: Dario Binacchi --- drivers/net/can/slcan.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 956b47bd40a7..4df0455e11a2 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -428,11 +428,17 @@ static int slc_open(struct net_device *dev) static void slc_dealloc(struct slcan *sl) { - int i = sl->dev->base_addr; + unsigned int i; - free_candev(sl->dev); - if (slcan_devs) - slcan_devs[i] = NULL; + for (i = 0; i < maxdev; i++) { + if (sl->dev == slcan_devs[i]) { + free_candev(sl->dev); + slcan_devs[i] = NULL; + return; + } + } + + pr_err("slcan: can't free %s resources\n", sl->dev->name); } static int slcan_change_mtu(struct net_device *dev, int new_mtu) @@ -529,7 +535,6 @@ static struct slcan *slc_alloc(void) snprintf(dev->name, sizeof(dev->name), "slcan%d", i); dev->netdev_ops = &slc_netdev_ops; - dev->base_addr = i; sl = netdev_priv(dev); /* Initialize channel control data */