Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1413861pxk; Fri, 4 Sep 2020 08:48:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXNoGsGDwFRQlfkgm5t7M5unUwGsNrI03Bt/+f9cN5u0OIONlQ9Qs+rpdAZGo1RLYaM4FX X-Received: by 2002:a17:906:f950:: with SMTP id ld16mr7872496ejb.489.1599234527319; Fri, 04 Sep 2020 08:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599234527; cv=none; d=google.com; s=arc-20160816; b=ntOscZIeDWBjeg0AUpPZu/ThakVk1nsIJK00CkN19Xhlf6G/xqtRGYh+G3V0anUSk3 Fha5G0yklnGkKvUfV9D2d5CEphnRkAJYIaWTFST2eGmfWYZOybiRhKMLztpUxWLJH9sx kZg5LmMc4Ls9G1irYnt8UclvbQvKvBRPTO57nPD9DYyTDP8+qf417HSYMJqUajst3LMl PMbFwZzmpDSR+IgtP7N9AIRACDSI2GHek5l+n/Pn5t5ZRhpPiIK+FSUTtO5zgM55yLDP ISgR5DaBFEhMtdyc7cFP6OuvXI5ZY+6+PyQQPOe6xTW3YmwH0gsAGjgCvRpG1693x64v IZ7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZXNzTcdhYOLT/AXbUue/WL7HnvjNCgkZ3cLbmDzVGrc=; b=I8KCRhQw00pOgFQ1A0B+RAsa2CsD6kjYyf9LwHoX5dVn/fVQgdSFuI7E4yA3m/nmg0 XyAIFIZffB7NTnpYCwIRHsdMgBawdvmhmW40wpnLHaJaaAJ1z5F56+/99vWnH3nzHdBp NUx+MdHrXHgwM3HoNO2PJzuotnlGk3hxTQmC7C5MPXr3zQ/INS6rd88IA82ipGNRXTX1 AtwnIDskvaKM4xEZqeT9nGSHAKx+k3cxTwRXzeGg2Grg3kshw+veYaWmbjOCL53Px2jf Y+9tyrlepfbRtv1jPg+9q7DINsL5yW1hPX5rZ972Ipc0JRhQl5n2jotNgT+YJg+tVfTD 49TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=RrJg++r4; 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 c19si4380307ejz.484.2020.09.04.08.48.22; Fri, 04 Sep 2020 08:48:47 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=RrJg++r4; 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 S1726511AbgIDPrc (ORCPT + 99 others); Fri, 4 Sep 2020 11:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbgIDPrJ (ORCPT ); Fri, 4 Sep 2020 11:47:09 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42948C061231 for ; Fri, 4 Sep 2020 08:46:50 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id a9so6523219wmm.2 for ; Fri, 04 Sep 2020 08:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZXNzTcdhYOLT/AXbUue/WL7HnvjNCgkZ3cLbmDzVGrc=; b=RrJg++r4d2sHRcNO3FHpdXscTwZC2S1z6mTa4gXaNzK1juMkhcaKgspDfWpLneE8ew tHNr9Istt1yOiqL4bpXNH0QTSrkeP/0+Sm0lWzrBSnNzA8Ipt1xnsSsJLqMRrfXfgPdL ByP89m21osn8Id9E+Wyld2kuBz/37527FByOq0o3H71SYeQv7QKjZwhPK8OLk7ZZ1+ln E6BINQjI5QOfdhbly6Mg+N5QR3sey2pYn/ItHPnMoSmlC2iJkFNPzpvM5K7zwL6RYcjj gqdPy1/YiAdUWwlNY/7Qrbz14NPumdr00luxiTymMknoqxMZo8w0KTk1eN2juH0xrC0s 99hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXNzTcdhYOLT/AXbUue/WL7HnvjNCgkZ3cLbmDzVGrc=; b=SwWLAJBrD4UkIi6ue2ib4PiyMzFo0fp0ExSM4T2dd/PZcSBnOGgr1+bBuLiJV4MgQY xZoKcxXnN1wGiKYYnG3a+8QnPtYpNiCGoi0ArUABm4r8I52VKAacu2hsjR8RPY6xwg+g Ct00qD1JNcWDnxFwI7yvmICiCur9CcwVqxOOgkQeryfhZbLBz5AvyiUvdrCZXbP3hBf3 b0dZ42hqWvFJ2608vwWgBekxi367HSryI5cWa7BC+MKHLvp5PUza6pK0Zsqdu+BF662C fK0W42o1lRx5kSr/LGa5Zd7egHy9LYXc/yW1EEzl3OfWy8mu6Aqbs9Vdbw6VsCpxE9qw SSIA== X-Gm-Message-State: AOAM530DqPQXFxQLLycGEbzeTFN68CkEUpJtBkKN3hqMzSpuzP4Ya2rU Th81xFKOaxI5bt6ZhJGALWvIkw== X-Received: by 2002:a7b:c056:: with SMTP id u22mr8253559wmc.188.1599234408930; Fri, 04 Sep 2020 08:46:48 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:48 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 15/23] gpio: mockup: use dynamic device IDs Date: Fri, 4 Sep 2020 17:45:39 +0200 Message-Id: <20200904154547.3836-16-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski We're currently creating chips at module init time only so using a static index for dummy devices is fine. We want to support dynamically created chips however so we need to switch to dynamic device IDs. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 96976ba66598..995e37fef9c5 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,8 @@ module_param_named(gpio_mockup_named_lines, static struct dentry *gpio_mockup_dbg_dir; +static DEFINE_IDA(gpio_mockup_ida); + static int gpio_mockup_range_base(unsigned int index) { return gpio_mockup_ranges[index * 2]; @@ -480,8 +483,12 @@ static LIST_HEAD(gpio_mockup_devices); static void gpio_mockup_unregister_one_device(struct gpio_mockup_device *dev) { + int id; + list_del(&dev->list); + id = dev->pdev->id; platform_device_unregister(dev->pdev); + ida_free(&gpio_mockup_ida, id); kfree(dev); } @@ -587,12 +594,19 @@ static int __init gpio_mockup_init(void) } pdevinfo.name = "gpio-mockup"; - pdevinfo.id = i; pdevinfo.properties = properties; + pdevinfo.id = ida_alloc(&gpio_mockup_ida, GFP_KERNEL); + if (pdevinfo.id < 0) { + kfree_strarray(line_names, ngpio); + err = pdevinfo.id; + goto err_out; + } + mockup_dev = kzalloc(sizeof(*mockup_dev), GFP_KERNEL); if (!mockup_dev) { kfree_strarray(line_names, ngpio); + ida_free(&gpio_mockup_ida, pdevinfo.id); err = -ENOMEM; goto err_out; } @@ -601,6 +615,7 @@ static int __init gpio_mockup_init(void) kfree_strarray(line_names, ngpio); if (IS_ERR(mockup_dev->pdev)) { pr_err("error registering device"); + ida_free(&gpio_mockup_ida, pdevinfo.id); kfree(mockup_dev); err = PTR_ERR(mockup_dev->pdev); goto err_out; -- 2.26.1