From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F98FC4742C for ; Wed, 4 Nov 2020 19:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 043B220709 for ; Wed, 4 Nov 2020 19:31:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="RaExq3uc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731704AbgKDTbV (ORCPT ); Wed, 4 Nov 2020 14:31:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731594AbgKDTbI (ORCPT ); Wed, 4 Nov 2020 14:31:08 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40594C061A4A for ; Wed, 4 Nov 2020 11:31:08 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id x7so23325879wrl.3 for ; Wed, 04 Nov 2020 11:31:08 -0800 (PST) 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=uGxknteRFmc8uD8KRQwE2bQfaW1TLGwQ+1UoD3santI=; b=RaExq3uc7wgceJs+w6qfXW0zxCXfChfmuBZ5fIfJU3dTl+CuEheFyuWIDdpdwwWIe7 YG1psmFGrf3PNz/aPHJie1v065Y19OUTUKIYruuL3qY0Fotesa7peV+y2WwxR3zSCDFS kYCA8MP2Juxj2G2N5j5DZMNFrn+mvrKsxQRGjV9A1RXoYoG8USzSTkFN+oG2UXEGVhKE 1Nc337PRGnV/cahRPeQfGuAIEI48jAApXf3TUEMT3yFcZWSF88MTJgeWgdHYv2LvvmLS SHTU6/xVCA1r6lTp0COmmk16T4bLd3d4s6wy3zdwTKO9Iw4XauXHEsgx/QE1JC2WASGF l4wg== 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=uGxknteRFmc8uD8KRQwE2bQfaW1TLGwQ+1UoD3santI=; b=jPenRYzf3x9L298uwrqWjMsbfVBfdqr86sW2BVRPSLOmA1q0juXr5K5fTXZxcvfKrK OK+bj9XZms6WK8aiROAWwhK4WCQBmDJBOJIlgQ5bmVsF4sIlaJFBJ55loWa4G+n8D9fJ gHt46RptGWxKE3JdCmabqFlAXSrOYecJ3jDtc9AtCycRk93J2snZlxCgNTPo4nkpq5z7 I+oK1kSmgeSmozAbEMnKnUz0XRcaK1kN67wwL/qwSLA+xIo/nC4/Y+HEnbm3BaklEW9G xDkb/VTpG7KYPll5+Tdyz3+aj5n71L9Y4HSmc1rgD4CZ9XpC5d+mKA2XJQCx9LzzHvB8 /KCQ== X-Gm-Message-State: AOAM531zC5/2kOssPRhqU1PDOCp+hO3NrY6eyrkPYuKaaF4f74vt2VWj fiR8S29XYi5syvWu0jCvLyK3uw== X-Google-Smtp-Source: ABdhPJxNzRzC856EUc6D12iZqJpjACECxzwnA9OtvmVdnej2G06cWHMRMwspZChWQGhIav7w4CBkmw== X-Received: by 2002:a5d:4883:: with SMTP id g3mr18433798wrq.19.1604518266966; Wed, 04 Nov 2020 11:31:06 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id m12sm4051671wrs.92.2020.11.04.11.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 11:31:06 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight , Mark Brown Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 8/8] gpio: exar: use devm action for freeing the IDA and drop remove() Date: Wed, 4 Nov 2020 20:30:51 +0100 Message-Id: <20201104193051.32236-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201104193051.32236-1-brgl@bgdev.pl> References: <20201104193051.32236-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski We can simplify the error path in probe() and drop remove() entirely if we provide a devm action for freeing the device ID. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-exar.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index 94ef500567ef..b3372279188d 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -108,6 +108,13 @@ static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) return 0; } +static void exar_devm_ida_free(void *data) +{ + struct exar_gpio_chip *exar_gpio = data; + + ida_free(&ida_index, exar_gpio->index); +} + static const struct regmap_config exar_regmap_config = { .name = "exar-gpio", .reg_bits = 8, @@ -155,6 +162,10 @@ static int gpio_exar_probe(struct platform_device *pdev) if (index < 0) return index; + ret = devm_add_action_or_reset(dev, exar_devm_ida_free, exar_gpio); + if (ret) + return ret; + sprintf(exar_gpio->name, "exar_gpio%d", index); exar_gpio->gpio_chip.label = exar_gpio->name; exar_gpio->gpio_chip.parent = dev; @@ -171,29 +182,15 @@ static int gpio_exar_probe(struct platform_device *pdev) ret = devm_gpiochip_add_data(dev, &exar_gpio->gpio_chip, exar_gpio); if (ret) - goto err_destroy; + return ret; platform_set_drvdata(pdev, exar_gpio); - return 0; - -err_destroy: - ida_free(&ida_index, index); - return ret; -} - -static int gpio_exar_remove(struct platform_device *pdev) -{ - struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev); - - ida_free(&ida_index, exar_gpio->index); - return 0; } static struct platform_driver gpio_exar_driver = { .probe = gpio_exar_probe, - .remove = gpio_exar_remove, .driver = { .name = DRIVER_NAME, }, -- 2.29.1