Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp299020lqi; Wed, 6 Mar 2024 18:43:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkoX94TuFaFRPFx1Wf8JuY1HvMyDD7p+D7mjkCDJ85fvolMevBx2upAUCPnYoStPRDCsvfXdbpim3Vw7FNAa43Rc8Y3GDtQdFdWdxMng== X-Google-Smtp-Source: AGHT+IHMPFLzE0mZG2sVZeZt/bdjC/IpX3+POhZdJp2itIqKYb9O34dgyeUfV0h2Di55dvNY0CqV X-Received: by 2002:a17:902:650c:b0:1d9:4ede:66b5 with SMTP id b12-20020a170902650c00b001d94ede66b5mr5878294plk.15.1709779393107; Wed, 06 Mar 2024 18:43:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709779393; cv=pass; d=google.com; s=arc-20160816; b=pJy0pTefkL4AKC0AXzeYLTq0XWNuBy8beF4wCTrciQBELly+QdxWp1luqbscEyGzjK emtu8j1s+5taWjTUW2RHdEU/bqef0NkNZxJP3UbgTEnNCOqDQ1Y5kp4YXjvh4fUE5tzS KnRV8iBxb5IryY/R835iK1wMBQaQDE/gMCLOhATJvc9RsQWzPreobXhvTLfw/I57mOdN g1uVh+fCQ/kxAIXRiP0Ry9G8MWgBYN/Y6+70PjB9VWvIjmf3oz4ihEjI/TqFXwAFaREP Ni+n+CgFQEpZAXNtG5/BGu6s45CdFdsOEx0lJTJ5X1MkNdWrOMnkSURkWQj2MiGKRsuw 4UoA== 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=2TCgDUABLhnN+B3LhAvwj3wO9TJloQkaRFwwXQWooLw=; b=aROHFckYH2qqWWW3KTMbQVH9gIoFkYp6MRUak8T/kRdDrrIaE/KShX6Wx20lznXcu/ vjIdRRH+3SXQeICn0vIkGB3312Bqm3+6SOIeyopeB3yBrlNa/SDCnYVlpvjO6D5PWvEk f3wMG+uGmRUJ1QfV7iuBuneFrKysthQu9EGkabHlTtJ13BfI13M4fkJidog6RyXPZb9Z KP6G4fNMEufFpc93bECMa2MODv1ApTJhwCTTGJg/8Nhw459yZgzpqIGxTXtpsFLFCpb2 jSl+nRTPNOY29W30S6sR1+5q9lsWmVXG7OclACzQakj1mUsCIFc6RkOx8Y4hYsMG9S7O VHUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=OWWNzuij; 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-94878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94878-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=salutedevices.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i2-20020a170902eb4200b001dc91f97b58si12336592pli.652.2024.03.06.18.43.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 18:43:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=OWWNzuij; 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-94878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94878-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2CE71B22403 for ; Thu, 7 Mar 2024 02:42:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07D8D1CD21; Thu, 7 Mar 2024 02:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="OWWNzuij" 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 634A363A5; Thu, 7 Mar 2024 02:40:54 +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=1709779257; cv=none; b=qKHc3YbnaxG5Yd/XMy09I4rTC73oDIUOSxsMPAO4oBcSlER4WBbvbKeXB/BbwaR6SA46j4b0y118MCLjGRSEDUNWjDia4WoXZp7gYCbbOM2C/vhamjgt2wwXtDk0RPOT9jpbRp0JTmBaRd/eXzkOHRyLkzY+VjHO3B441P2l2Pw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709779257; c=relaxed/simple; bh=pMOgNp1DtB4n4llksf8GEmN9pM3NbcpZqdPQK42zEpE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ki1qTo956OtG37GUZfdvm0h/mh2yJvOKm8IqxxrG6I7vAa5iDgO2EMayEOiCqyDcBsF6wmv8r4DFE5NU5B9ZVqnai82GXLY7vRm4qFAXDoe5oGyF/kTTaeaVeFSvQ+A6SCA8zczWPCcql/Vnd2EImqLt+DafZbXYx+YSj72iDqc= 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=OWWNzuij; 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 3EE2F120024; Thu, 7 Mar 2024 05:40:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 3EE2F120024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1709779246; bh=HLNCTgwzZsqdyYp20b9aN7SyO2BGd0FTbWWmDldD028=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=OWWNzuijGzDEqz3yM/fY2ooLqZkKZC0nh7P1LtNQjQ/b7n24oA1E3kJUdB12X1jbj Sb5A9hkX+cOeRoLf8FMa1ozsaF57q3MZFhY2fE+YLwWtZb0L7GGwW9hhqKDQyK5ZzT lXBt6UoVp1Gc3vPqa0SjiBtP4uaGu4qtBE/pX51p7ytrpq3G/d1Mqsw9yGIVdjQg0i H3eiEhfcvVVp9/3Xdgsr6x+12mJfG0LtoQADcImPWwsMZguK2YXkLfHcl1lROjappq i+D7KJ5pVhXLuQMxjFxaQWZ/Y+TBpN0dOTh0nXoLwc1R4vpWFxNxI0Y5aKmmqR7JCW ihRmGX7NmD1LA== Received: from smtp.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (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, 7 Mar 2024 05:40:46 +0300 (MSK) Received: from localhost.localdomain (100.125.24.169) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 7 Mar 2024 05:40:45 +0300 From: George Stark To: , , , , , , , , , , , , , , , CC: , , , , George Stark Subject: [PATCH v5 06/10] leds: lm3532: use devm API to cleanup module's resources Date: Thu, 7 Mar 2024 05:40:30 +0300 Message-ID: <20240307024034.1548605-7-gnstark@salutedevices.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240307024034.1548605-1-gnstark@salutedevices.com> References: <20240307024034.1548605-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-a-m1.sberdevices.ru (172.24.196.116) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) 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.125.24.169 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