From patchwork Thu Mar 7 02:40:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Stark X-Patchwork-Id: 778996 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 680A51C27; Thu, 7 Mar 2024 02:40:52 +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=1709779256; cv=none; b=sblV196yRZPBhH9io5UffXl40dDASbzMaQIt+ipCamRcbRD1ah2ez8Cnfh2Xa4XRhvjzh004gl5IdKIYJo3l3S6KBXt3z26BSBGtW7L+41tnzcbYUh5OrwMT6wU4R4xJpToyQaDQmUIFvEqRFwXTQJerXLES5X/XkHakBnilObg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709779256; c=relaxed/simple; bh=pBPynPtz/V7v/h5wuWtgu0O4YV1eNNCWoKb2hnz3ZPk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EzQey0ss4I0LpIHvME1vLo5hpTmvUy9BGR4A/hZC0rCGLXl3LwpyFYLyFBQ0ekg23pKo/PSv2yN5XuRzTULb+gnba604MUAwY3BiKWEwPNj+x4Acbg36rmYSz1DW2oOFyjwH7zzEkq30rbsECM+2PeUgUMzkP1MDR6Bbb/AbiiM= 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=vtfXGAQ3; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="vtfXGAQ3" Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 8256F120021; Thu, 7 Mar 2024 05:40:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 8256F120021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1709779245; bh=gPoYxl99hZw4r2GrN+UX1NkBh/kze2TFpy26yv3N7sw=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=vtfXGAQ3hrwUHgW0YKhiJaXoT8leKfVpXR+Z3J1UJpafb3gPvsfB2Q0EuFQv6s5CE J1Le5Xzzo28siZ9fEQw6OVf68dJGh3VPcW3EL3Fc1cBqmOXXWRMjCDGlV9xm8Jp47S 3y83p1ybkSzi8v9OcgWezZV2Ixtv1HS7RJ2k3qiJebWNQw7eOnHmt4MlGY/U8DTYjK i4uN592ubjzBdlUqWG5ZUn3j9ygjelCpyO7riXWDt5tSlsgn6aUIWCq0OhiUjGeJwP gf/gEUgA5tH6zeFPHgXX8pr3l4D8BBGVFwmN89U9/etGjQ2DcZNS/hyG8BlB8AxI3t 9btS69O0ZR7GQ== 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:45 +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:44 +0300 From: George Stark To: , , , , , , , , , , , , , , , CC: , , , , George Stark , Nikita Travkin Subject: [PATCH v5 03/10] leds: aw2013: use devm API to cleanup module's resources Date: Thu, 7 Mar 2024 05:40:27 +0300 Message-ID: <20240307024034.1548605-4-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-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tested-by: Nikita Travkin --- drivers/leds/leds-aw2013.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/leds/leds-aw2013.c b/drivers/leds/leds-aw2013.c index 17235a5e576a..6475eadcb0df 100644 --- a/drivers/leds/leds-aw2013.c +++ b/drivers/leds/leds-aw2013.c @@ -320,6 +320,11 @@ static int aw2013_probe_dt(struct aw2013 *chip) return 0; } +static void aw2013_chip_disable_action(void *data) +{ + aw2013_chip_disable(data); +} + static const struct regmap_config aw2013_regmap_config = { .reg_bits = 8, .val_bits = 8, @@ -336,7 +341,10 @@ static int aw2013_probe(struct i2c_client *client) if (!chip) return -ENOMEM; - mutex_init(&chip->mutex); + ret = devm_mutex_init(&client->dev, &chip->mutex); + if (ret) + return ret; + mutex_lock(&chip->mutex); chip->client = client; @@ -384,6 +392,10 @@ static int aw2013_probe(struct i2c_client *client) goto error_reg; } + ret = devm_add_action(&client->dev, aw2013_chip_disable_action, chip); + if (ret) + goto error_reg; + ret = aw2013_probe_dt(chip); if (ret < 0) goto error_reg; @@ -406,19 +418,9 @@ static int aw2013_probe(struct i2c_client *client) error: mutex_unlock(&chip->mutex); - mutex_destroy(&chip->mutex); return ret; } -static void aw2013_remove(struct i2c_client *client) -{ - struct aw2013 *chip = i2c_get_clientdata(client); - - aw2013_chip_disable(chip); - - mutex_destroy(&chip->mutex); -} - static const struct of_device_id aw2013_match_table[] = { { .compatible = "awinic,aw2013", }, { /* sentinel */ }, @@ -432,7 +434,6 @@ static struct i2c_driver aw2013_driver = { .of_match_table = aw2013_match_table, }, .probe = aw2013_probe, - .remove = aw2013_remove, }; module_i2c_driver(aw2013_driver);