Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp405235lqs; Thu, 13 Jun 2024 13:34:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXk9rtvsY3J0ithlcxnrG0+/cQVc/96M0N3hhaJ/EfQ1k80iPgakJfUjE5bGJscGSiHCstDEe6GjY3t5/6oU7CP3m78adIt2mrNXpozvQ== X-Google-Smtp-Source: AGHT+IHVPpds7c3VbaE+IgpLjOKK7TXDvj+J/zu0kUXvNmuSU8huL+I2sWACyd+rUy4KddHCHuDk X-Received: by 2002:a05:6870:96a4:b0:254:cfd7:4f91 with SMTP id 586e51a60fabf-25842af6b26mr803006fac.45.1718310859937; Thu, 13 Jun 2024 13:34:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718310859; cv=pass; d=google.com; s=arc-20160816; b=nvyD/8JFcYlpRG8TNsxFYAgf/gts+7hJHt4g5dg1VMMR69RAldRl4vIc39XCJ7skLk 6BEPqiBivluaGuThJh5sUqSBojojBa6Ub8zTCye2diJ/BLqaus39ZEu2KpARKt7TfIrE a0ve78atosxWeXLaISDfkM3rm4ZyGxXt2zidGeIG79mSi6SSW47e+27LvgV4wDuzsg3W Bh0yHWrZpf95RV6u9cPMM6bdmmqsab3HkuHJAeIaZ6P3cd5BY8nchE3I4EWwgNSHB0ks htkFKKWmudInWswYBwLk6J45PzOJuMK3Xko10wEhmHnRCEgX4RsW4RMpu4xokZmRSFwN 3rqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=T+Z+Sh7QNMFt+l8WJsmFcB+QJVi4sJIubORyXipYrOg=; fh=+5ObgQnrCkea1AHxgRSNW3c6Bs1CPpqLGLF7R+P+iUs=; b=0naGdXyBUTGkSGmyFIutXi/I4lUkbCo9qaMmRzDJvjB+SnQjqwkvDOm96eaib1ECce IidkDpS7eupGiTz83LvGlHIFpuf57qhOD+M3NCOV34x6DYwDOiextzfYbwRhHF3Fi1qF z1AW3+qyShVrf7PahnJeIHnRkIOFfosp4NbZI/i81C8FJf6fzWxZmeLmEo/Fl5Q00U/B sOAcgXVfvnI7MBYEch9GXiplkbxC3TuFqLN6JvJzmjdNUkua1+7y6donS43zF2O9kDck 7YsTD/NfMcruZU37uepaRMgawtLrKOhHM2f1BmRxwJ4T5OzXkUzukVvkkwcY5sC1hgad eLdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=qVIo4kfU; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-213976-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-705ccb95f3bsi2138675b3a.300.2024.06.13.13.34.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:34:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213976-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=@weissschuh.net header.s=mail header.b=qVIo4kfU; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-213976-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net 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 7B4F2B25113 for ; Thu, 13 Jun 2024 20:15:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BAC813AD27; Thu, 13 Jun 2024 20:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="qVIo4kfU" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 A8FC612F37B; Thu, 13 Jun 2024 20:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718309737; cv=none; b=U6Qns5ywqYFbWxr2B3cpzqFaiNZmOqdHfmM3pIvFWKgRUcFO8RJOlvunYoiIukPIJBnwUf6ofeot0R44Th4YGZJc777kw4fjoe4ErmqVU5te3BIgKCg2wWKOR1kqHOcoebUU+Qg0Gxri3UCHbiOj/k0p5zPRYE655qno2Sfr8NY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718309737; c=relaxed/simple; bh=V+7rNBrVBMiquqsDaHIG89BLDRn+4swfipLg+5xOqn0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=vBhU4TwSc1w8wb6e35vcsTcvpiE6vuvjDWh6DgDZRZppqXFZ+qv4S+IWRj5P2FjUcxLfwPrDdsneINIJrmvijE9IVIR3KL3dzR4iBgUbEdsrvTT9IHmXg7HHGADVe2OkWN2JA+BBu3DiPl1VqiW1P1+FBFWJp5LmrTp3jyiGLos= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=qVIo4kfU; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718309732; bh=V+7rNBrVBMiquqsDaHIG89BLDRn+4swfipLg+5xOqn0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qVIo4kfU0Fsy9ywTFamSR9/eOzVb2gWHpVzthTCpEi1ZYrL6EhJ1Mb1degz7Iyp3U cxSOxuAajCGTGoZ8Uwdtr57WjNn8uSXDF7EfThlkBuPywMqFp1l7/y00gMtdQP9oo4 0WWe84rX6FM56FK0Sfazv11vbqgklylm40zOJM60= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 13 Jun 2024 22:15:33 +0200 Subject: [PATCH 2/5] ACPI: sysfs: use device lifecycle for _STR result Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240613-acpi-sysfs-groups-v1-2-665e0deb052a@weissschuh.net> References: <20240613-acpi-sysfs-groups-v1-0-665e0deb052a@weissschuh.net> In-Reply-To: <20240613-acpi-sysfs-groups-v1-0-665e0deb052a@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown , Robert Moore Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718309732; l=1932; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=V+7rNBrVBMiquqsDaHIG89BLDRn+4swfipLg+5xOqn0=; b=1FnIhB0nONyobBwXP9cfdPRxo46K7f9X4+4wRu9l3XogLAy9UzjQdGbX4CcS052uoU+rzXphK JU2Wf0F3gjSCfLsCKAWwGDc/a2qTC64v6VsRoIjKqDAiE5iyw24asNf X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The string assigned to dev->pnp.str effectively shares the lifetime of the device. Use devm_-APIs to avoid a manual cleanup path. This will be useful when the attributes themselves will be managed by the device core. Signed-off-by: Thomas Weißschuh --- drivers/acpi/device_sysfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 4bedbe8f57ed..d0ca159d93e1 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -494,7 +494,7 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(status); -static const char *acpi_device_str(struct acpi_device *dev) +static const char *devm_acpi_device_str(struct acpi_device *dev) { struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; union acpi_object *str_obj; @@ -522,7 +522,7 @@ static const char *acpi_device_str(struct acpi_device *dev) buf, sizeof(buf) - 1); buf[result++] = '\0'; - ret = kstrdup(buf, GFP_KERNEL); + ret = devm_kstrdup(&dev->dev, buf, GFP_KERNEL); kfree(buffer.pointer); return ret; @@ -558,7 +558,7 @@ int acpi_device_setup_files(struct acpi_device *dev) /* * If device has _STR, 'description' file is created */ - dev->pnp.str = acpi_device_str(dev); + dev->pnp.str = devm_acpi_device_str(dev); if (dev->pnp.str) { result = device_create_file(&dev->dev, &dev_attr_description); if (result) @@ -632,10 +632,8 @@ void acpi_device_remove_files(struct acpi_device *dev) /* * If device has _STR, remove 'description' file */ - if (acpi_has_method(dev->handle, "_STR")) { - kfree(dev->pnp.str); + if (acpi_has_method(dev->handle, "_STR")) device_remove_file(&dev->dev, &dev_attr_description); - } /* * If device has _EJ0, remove 'eject' file. */ -- 2.45.2