Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1604562iof; Tue, 7 Jun 2022 08:30:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkMQ7kEnqmC1AF3di/9q5Mpjt8QLGc3uBeLr62D6zk7cWnkJ6nllYMcNvlCUae0YXI8udS X-Received: by 2002:a63:fa15:0:b0:3fd:696e:b432 with SMTP id y21-20020a63fa15000000b003fd696eb432mr15006561pgh.320.1654615809812; Tue, 07 Jun 2022 08:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654615809; cv=none; d=google.com; s=arc-20160816; b=mX2relcA9qwGDVNRcdBJQniFF4l5/EoCkOEv5uInnW42a0HxJr940mxto/nbITrKYK nX5CFBdXYrom+EKoJoqn78Y45jRv0Whj+HtkE3yjqnR5dS8xJVJ3U9wXbsS3eNE87kKI edZlahuMCMi/PMFO8jasKu5WS3Wc4Xnmxf/CQxQx/D8Yf0L/R/IdGH/oQzQXNKw3B8fT 9eyOHeJfO9q4hf+TeMWoWpRhW61DUGoNsImDusTV6M2fZoap1+ghRdUntg8y44q7rIZI pF0WvbaNfEKqTCQ5AfSm0FsyGACo7OHemFJifyeYNfsz60rYi7vs1QgRpM9F+QJbO+X/ 0GVA== 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 :dkim-signature; bh=flkxolnPRJ/fuZI8sau+S8LRxDQCGOpfvcgrJTeckZE=; b=Y1+dWJ2KfR8GK8+LXiwmUItugRWLxXo395mnsByOa4YGLVK/KcvNdD2dZYPmZ2/xMv ib6+akjqdsbUCBUxYj/g/lXJzZKrvM4oHoThWy326zBK4Cc4VKZY4Sxm23OFRK9X3Ko5 cArLMVx4b1vPG/cXzOaXzcSR06LJGkIEHxsTTA/Ytrb1jOCO6Ngrv0a2mGqF/HFrC2Iv 6zy9ctgZ1J1QKKXM7PYTHnCIXLKFfG2008XWa+DuOsGcSqI3EcOaxXGwjzqUpugEwS/h 42XpA5d9WoXc5wfx81aPiPlBp8GNWo5bxl8tQOcUU/L2gBRHvgM/zOk3lmmy94wqWwEC Y4XA== 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 linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a63e343000000b003f5d5bbf0b1si22038722pgj.245.2022.06.07.08.29.56; Tue, 07 Jun 2022 08:30:09 -0700 (PDT) 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=@amarulasolutions.com header.s=google header.b=Iqu6UNp7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239682AbiFGJtB (ORCPT + 99 others); Tue, 7 Jun 2022 05:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240004AbiFGJsX (ORCPT ); Tue, 7 Jun 2022 05:48:23 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ED31DEEA7 for ; Tue, 7 Jun 2022 02:48:21 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id x17so23353759wrg.6 for ; Tue, 07 Jun 2022 02:48:21 -0700 (PDT) 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:content-transfer-encoding; bh=flkxolnPRJ/fuZI8sau+S8LRxDQCGOpfvcgrJTeckZE=; b=Iqu6UNp7gSNd70V5LQt4JGyekjdaLPSRtvVkcjkxJM3ev6IH4ZfqyXfFTsVVCEBCRo n/D5xOUWT9XepBqui6E3cPm5nvsR7cM9ZQunaiDCPtdQaj92yIRIteiETA79F7+rLe5a GYEy0bqoYg9i+vpD7i+37FTf55tOoE21SrcRo= 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:content-transfer-encoding; bh=flkxolnPRJ/fuZI8sau+S8LRxDQCGOpfvcgrJTeckZE=; b=WDThJzbXqZAorAGrMJMq3ByXibMvf2kEgNi9ZJF3cv0CuL4n+iSmHK0Sp3AoiJF4+I mikB160JlIVGiJ0HFq6c8pycuuWFnZOQ+aIylb/lNiVRO75aKlAYaykRSKiTCkN5eVe9 ++dgCn2OC3NPSVRnrUK3fg9/yoytfsS3pZm+6kGSr5VJaIs1DJnAkqrzLo2wUm0OCzHz +X7UETAUPe8mezAaZ8ILAGzi5piuDEYyozmZ8+tSP6Zn3Q7qgKm/mW46qR8smD3It6hT cMhlT0L2IazMvGmF0UJbq5E7Ir9w9VOeR29AquT6+m5vCuj3HS+yXPohDACvDkCGODSi eYLg== X-Gm-Message-State: AOAM532RmvwWSE2OfaALoaGTX6/K8aT0qnJR680H/NSVmICP+4pO3kcF /p+mFxUemYWBKTOugM1bgZiZdfwo6GjEgw== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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 */ -- 2.32.0