From patchwork Wed Jun 8 16:51:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2033 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 475863F1F7 for ; Wed, 8 Jun 2022 18:51:32 +0200 (CEST) Received: by mail-ej1-f72.google.com with SMTP id kf3-20020a17090776c300b0070d149300e9sf7261529ejc.15 for ; Wed, 08 Jun 2022 09:51:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707092; cv=pass; d=google.com; s=arc-20160816; b=PCqvguRS0J5+XuUw0y09NrRdDA7XGqWro1EWjA1BKKqY+sPQs4gge9MjibAjbocaSI pJQAVNGDOx6x3WNNzHcuiOUl15vytOElnWZLkAXHncAZvCgNL5tcz6FTEVmLIAU2B4CM YF5F2a9mRS/GowB1P63m6CnqnOmc0e0eYhzJeR+YKv1nqBLl4PjLJSgwFRR0NPBm+fkN RkJMtZpl1g6o/LWyWUapijMghMn9syz77b48PWerUNVkZvbi97IbPFNuB38EjOUmrpqE kM+EJ/ExOaYEha8wc7pkFApRo3K06ujkZJvIdVQZIgi39f6RRJwrSXjY34cW5cJ0Sb5h cVAg== 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=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=P8ZhUhw6Omd+dPqzp4pqpCei5+ghTSMLtFuHyIRHMycjWMjBwJujkJTZ8oKCeCnoIZ UWwoQJLoRqAAJTbRkMVU9vC5bLSxGtevwKjnE+x/5t0YJoc1iOZ4CQQowaX8orWN0D+2 Fz3hWJ+66x1Hq5oop/HP6uDTnA+/FuDdznT2bFCoFimMaHvUWQpq/BVaGrJ5zG7CDzPW iztxOkzVd2mL6hYWU37j/1rsk7DyOBQjqRpp+dAQOU6zZ9n35dSOqiXJOmB2MgyFSdLi SdV+NzCvRs6J8yPq95DV5VnZ87vg/7VAWB2vBACERgTmIIGv0J1TPcdZ3toYmv+xorTb RU3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EbNQlONL; 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=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=j8z6mmC8d4aJS1QclK/Sx5PtG/x2mIgJ4naklo57mlCe6TvGbAhOQjv/dDMKNJKvuV VApxILYcCa5jSQLDLTRa7u1xYYHhl9wIGy5Vdw7XspMnLVE8VYKn4LdOJALjDojNhol+ aBoWVtrukmrf700IJv2ZEQh0KKOft/zB6Eolw= 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=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=lG4CVS26T992wWnsKy/cLMSi5xK/fE5U4J+ce7G0FqLGwkLJkYT1wCeiWR96KJ4CLw kRTBucDFBtqh3cpUmpnlpi6pGenKdeYIEcRTTkBJwPxBJmyVgwwDDehvOt1cmHzJYvLO /CW9aeUghDIJMrETKeVXygyE23+Rq7pSeWTB9ATCQJuhM8IOIjj3/6FQ3ZJ2jIfYuZ2q imLpWGi/SmjI1m6JZffNmO7ZVd9jSSaWVwKmBPtrrkSe060fiz4MjYMC5VDbyJL0Jj2S kJYfHeDT7jDfdqK3Vxt8xuEkkGlAKyJOrcw9oTLVBRe3ES/RsNBWoBeAUPre5IZ2oRKV 2OiQ== X-Gm-Message-State: AOAM533wS0mercnRKdFmihBnmIbU/d4OfNhGUadJnnzm1XNQJ4C0tWpr eRxSdM7JlR9vUCS+fdNpPo7Ejpbk X-Google-Smtp-Source: ABdhPJw7Ksl7qNx7zNMvX7F+gs7UKG1BowxMIPIiiHYeBJllnk19hLx7xV2Y1RJnT8rh2u7nNnEScg== X-Received: by 2002:a17:907:72ca:b0:6f9:8675:6a2a with SMTP id du10-20020a17090772ca00b006f986756a2amr32650902ejc.98.1654707092100; Wed, 08 Jun 2022 09:51:32 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a26:b0:70a:1088:57d1 with SMTP id qw38-20020a1709066a2600b0070a108857d1ls1236926ejc.3.gmail; Wed, 08 Jun 2022 09:51:31 -0700 (PDT) X-Received: by 2002:a17:906:52c7:b0:6ce:a880:50a3 with SMTP id w7-20020a17090652c700b006cea88050a3mr32466555ejn.437.1654707091023; Wed, 08 Jun 2022 09:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707091; cv=none; d=google.com; s=arc-20160816; b=e3flWMP8wKCbE6mO9Wnk8MCTy4gPyiwiD5LwlmGKaliDKi53f+ecsohk1At3JmcHsa yBbkPgWXMPmu3W9ujoL6DhYYPANIhoQSYLuQp66NmfEdqhm1BNV4WgqEmzQtg+XiuTKI DUV+AEaPNbDpawsjy7qzyTAYahHfvdQS7Qx4d5Suv7Aqy/wF5ILeLB+wMYfwqWD4nvQ0 GDQadWtlaA0+PwbVnWMY8aKc/+W+q5pyT8Wo1vQBLjbI5HYW3iMP6NlvjgQhyFTIJDHw Yphv2dDxD7D+KvdBLibZA0RoXClB3Ovo46ZmmWuZRIhVF7I5J6O6eh9RcMhz07MrLCFw kPKw== 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=nVyQpX+Yrz3qKt1Nh+jQPIqCDb+sgmjzafkew5xQQck=; b=VQxBBSI4DsEWCToXyNYyxaqZqdDkJnRZ9Mvh3Zp4GxLxv2AmxsljWbR4P+/YgsICAd qjP78Db/1P9sKPgm/U0372LctTIfT148YqhK71az8hgZIn74BphIUD52bbGSR0DMn6Sl 9BAPpoXjQqOf+GPdDcA9xClC9TQSiz8N6wkQeE5Xdes5Zxe2rLsAt3rbxQy2nq4a3zwJ uxZqZ24EWnlc1EC8rlVIQ3rDR2U5dijW5AByfrd8sYTvaUTK2OZJD2Hlok9829L6HAPO GYotz6KHyhCozlKKGNDzCXdb19KeMR5sMWLJSRspwnwC2j/yP+lj0lhpXHQaLAKOGwSB fzsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EbNQlONL; 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 p23-20020a170907911700b00711eea1f458sor1707183ejq.30.2022.06.08.09.51.31 for (Google Transport Security); Wed, 08 Jun 2022 09:51:31 -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:a17:907:6e13:b0:711:c722:4fc with SMTP id sd19-20020a1709076e1300b00711c72204fcmr18014645ejc.253.1654707090839; Wed, 08 Jun 2022 09:51:30 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:30 -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: [PATCH v2 05/13] can: slcan: simplify the device de-allocation Date: Wed, 8 Jun 2022 18:51:08 +0200 Message-Id: <20220608165116.1575390-6-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=EbNQlONL; 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 --- (no changes since v1) 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 929cb55e08af..cf05c30b8da5 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -432,11 +432,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) @@ -533,7 +539,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 */