Received: by 2002:ab2:5c0e:0:b0:1ef:a325:1205 with SMTP id i14csp248736lqk; Thu, 14 Mar 2024 01:48:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWB6+pr9ouvht7fziICNCi0ozmSsfIVgZAeiX8jBPn3y1xN5PzoJiMOj7o6uLQ3wo2qj3mIfC8T1y4ifJRRV4CyhVYD1unZwcXMo5VpIA== X-Google-Smtp-Source: AGHT+IG321zZoKg3fu/soMoITF9nS72Wv/M4jywq6F9gBVj5YkvTPZygWgIdb+xKid3apptpmfMy X-Received: by 2002:a05:622a:1707:b0:42e:f5dd:99e1 with SMTP id h7-20020a05622a170700b0042ef5dd99e1mr1938125qtk.1.1710406121477; Thu, 14 Mar 2024 01:48:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710406121; cv=pass; d=google.com; s=arc-20160816; b=EUp0ziAAy3HB04s/Tjn4qOqlrlmkqTySdPmdV2ZBrCTXX0pGl/ihV5tSHwLJLWQqU8 QSbQV95VosK5eU74jj155svx6FwtJM6zUv1gPWgOmJx0tPpaF1saB3vT6rADYeh2mRkE /o3Mi/7S2mAHbdB8JDryKummuVT+cIwCj+Rsp8IVHOsfHvKz22+OSOXT9eb6fq3ZoNHN hpox0BxAp33NZ+73SSGmUskBxMMY+uN6x1sehnTeVGsUI0s5ZBiZKyUvyCUVn4L7dci+ 81jGIx6JUXvIuhx3PRXBmQbSVn2QTrRt7n/DcuiqOgFh8WBF5kUyU882rvwjBR1ywES/ CeVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=HLNCTgwzZsqdyYp20b9aN7SyO2BGd0FTbWWmDldD028=; fh=s1kWXXOKODOg8bNscCzUOYq9ohPIXtgB+6qODgig4jg=; b=YFYs3IoflgaB6AmLSbguxy839kQeslFcP+Ij3DaBTIWYO9IBXoTDHsL3RHyF41eEMg wej2u6bixAvm9NCO2KNu16cFjLitK8cEPOgdFLxU/vqlokW8SVPJQktf7p+QynMmZeHv VHx3J8IcKSTMIuqq8YffUi6DAzZcmUJnjc/Qywv2Gzslvg407aRVQCEipGrijYHJ7kE7 wzOI4xRKMyVZiUCwuNDMzGbtSkMTGr8d384EvgntWi5csMHLrVXMwHCl4dI12fiXdpIA qWuUCf6G2plYnhDWemezGJQ/lmAfAeJwTOuIOzteVZKU01MluI6re/LYdY9BmdInDD1T qjeA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=ahxOl+FY; arc=pass (i=1 spf=pass spfdomain=salutedevices.com dkim=pass dkdomain=salutedevices.com dmarc=pass fromdomain=salutedevices.com); spf=pass (google.com: domain of linux-kernel+bounces-102997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=salutedevices.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v19-20020a05622a145300b0042edaeccfe4si1015405qtx.139.2024.03.14.01.48.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 01:48:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=ahxOl+FY; arc=pass (i=1 spf=pass spfdomain=salutedevices.com dkim=pass dkdomain=salutedevices.com dmarc=pass fromdomain=salutedevices.com); spf=pass (google.com: domain of linux-kernel+bounces-102997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=salutedevices.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 12D2A1C20E59 for ; Thu, 14 Mar 2024 08:48:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B38B06EB46; Thu, 14 Mar 2024 08:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="ahxOl+FY" Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 753206D1D7; Thu, 14 Mar 2024 08:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.89.224.132 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710405984; cv=none; b=KKzdFWFfaGFwUZwSWAzA/qn5yu1stiPriLon1wUSZqtyQcJ1PYh1Al9Wq1fsbz2S8YzC/XlFcH7FdjmS74EIzi8PpRJkDxPtyT8gnx/2FSQehGEfBRM2Pvz74CF2INd8PvbN8kWFQYI/gv5ZhkCf/zxwAqaxOKKfiDLPBqGH7HQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710405984; c=relaxed/simple; bh=pMOgNp1DtB4n4llksf8GEmN9pM3NbcpZqdPQK42zEpE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n5CsKJlUk2UpTrwtbopJ+O/KMc1Cffsp8+UsJb7puFjXNpSGWyQPmCbh/FXI21isgRFdGg/9RpaghejNrKAkRtlT7wuxRJslcBUGNonC18YknqqRBadRIL5NZLe0FD+JhkPhmR31Rr+wIyObCvLZJhtTrxKIs+4I84MGV8/laAE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com; spf=pass smtp.mailfrom=salutedevices.com; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b=ahxOl+FY; arc=none smtp.client-ip=45.89.224.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=salutedevices.com Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id D28FF120014; Thu, 14 Mar 2024 11:46:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru D28FF120014 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1710405974; bh=HLNCTgwzZsqdyYp20b9aN7SyO2BGd0FTbWWmDldD028=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=ahxOl+FY3h1Uv5tYKMdCdjMv85duFzMGZgsuilG0nDULwvWDt/viK2nQGPXg37jBd YhyFsOOP9hCdJX9Ew7ykKZ1rkLt0URgZ7hSVrgrxVDeJO+FjPUSH9j83i8zB/IPJrP bGlnDRJkldD9tgdPifOry0WZMjGvG3FBzuRDOuDQX68cKgHJjPwg7MJrhPJa94Cu2L vdu1KOXEmUFNunDHJZG1r1DXht+q5effeFpZXlde8KjPLywjF5j+JMHcpwbyEHNN93 fCDKZoB4SXLz8ZfusdurGpIP7yp1DWfX9XbaT+q1fXxO1aVgTodM4MqXLyyZrHoTFA NFYr5zC7tS+hA== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Thu, 14 Mar 2024 11:46:14 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 14 Mar 2024 11:46:14 +0300 From: George Stark To: , , , , , , , , , , , , , , , , CC: , , , , George Stark Subject: [PATCH v6 5/9] leds: lm3532: use devm API to cleanup module's resources Date: Thu, 14 Mar 2024 11:45:27 +0300 Message-ID: <20240314084531.1935545-6-gnstark@salutedevices.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240314084531.1935545-1-gnstark@salutedevices.com> References: <20240314084531.1935545-1-gnstark@salutedevices.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 183875 [Feb 29 2024] X-KSMG-AntiSpam-Version: 6.1.0.3 X-KSMG-AntiSpam-Envelope-From: gnstark@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 7 0.3.7 6d6bf5bd8eea7373134f756a2fd73e9456bb7d1a, {Tracking_from_domain_doesnt_match_to}, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/02/29 19:21:00 #23899999 X-KSMG-AntiVirus-Status: Clean, skipped In this driver LEDs are registered using devm_led_classdev_register() so they are automatically unregistered after module's remove() is done. led_classdev_unregister() calls module's led_set_brightness() to turn off the LEDs and that callback uses resources which were destroyed already in module's remove() so use devm API instead of remove(). Signed-off-by: George Stark --- drivers/leds/leds-lm3532.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c index 13662a4aa1f2..aa7966eb506f 100644 --- a/drivers/leds/leds-lm3532.c +++ b/drivers/leds/leds-lm3532.c @@ -542,6 +542,13 @@ static int lm3532_parse_als(struct lm3532_data *priv) return ret; } +static void gpio_set_low_action(void *data) +{ + struct lm3532_data *priv = (struct lm3532_data *)data; + + gpiod_direction_output(priv->enable_gpio, 0); +} + static int lm3532_parse_node(struct lm3532_data *priv) { struct fwnode_handle *child = NULL; @@ -556,6 +563,12 @@ static int lm3532_parse_node(struct lm3532_data *priv) if (IS_ERR(priv->enable_gpio)) priv->enable_gpio = NULL; + if (priv->enable_gpio) { + ret = devm_add_action(&priv->client->dev, gpio_set_low_action, priv); + if (ret) + return ret; + } + priv->regulator = devm_regulator_get(&priv->client->dev, "vin"); if (IS_ERR(priv->regulator)) priv->regulator = NULL; @@ -691,7 +704,10 @@ static int lm3532_probe(struct i2c_client *client) return ret; } - mutex_init(&drvdata->lock); + ret = devm_mutex_init(&client->dev, &drvdata->lock); + if (ret) + return ret; + i2c_set_clientdata(client, drvdata); ret = lm3532_parse_node(drvdata); @@ -703,16 +719,6 @@ static int lm3532_probe(struct i2c_client *client) return ret; } -static void lm3532_remove(struct i2c_client *client) -{ - struct lm3532_data *drvdata = i2c_get_clientdata(client); - - mutex_destroy(&drvdata->lock); - - if (drvdata->enable_gpio) - gpiod_direction_output(drvdata->enable_gpio, 0); -} - static const struct of_device_id of_lm3532_leds_match[] = { { .compatible = "ti,lm3532", }, {}, @@ -727,7 +733,6 @@ MODULE_DEVICE_TABLE(i2c, lm3532_id); static struct i2c_driver lm3532_i2c_driver = { .probe = lm3532_probe, - .remove = lm3532_remove, .id_table = lm3532_id, .driver = { .name = LM3532_NAME, -- 2.25.1