From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27F213E073E for ; Thu, 25 Jun 2026 12:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782389780; cv=none; b=Qh8YRvy/IlCeiB2fM9wTJYusUqKA4IHAUbBbu9je489HyobJI6IYmwq218eYcSLq7lFa64CQIVvfQNwtKFwqGX4vRc/Sg+VW5Cm/KCfz508LePAoCcZYIOahQCjaGoi2iLG3J/6j6AHvEoaoMidowVdK9Ena5BvqiAbf3/MTE08= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782389780; c=relaxed/simple; bh=Q51q3+1nzHcLtThfBK/sUij3M5TX+iKxB/+fLsKtBYA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bkd8IQCjvo8RJD9jX2/YSG7JvxKXpsfXT+pLO/uP53uzrO9M/ttA4g6rKIfSRbuJVqigIpe/YOSm11Yd+5oJgRHtbOrumbqUCBQA0giLKzLes7kS3Z8AczDNjq5JtHnlzsBmA2cFnw8265/MedpDpufwKBWGGHpLorJsX//RN3s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ceJ3v2iT; arc=none smtp.client-ip=74.125.82.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ceJ3v2iT" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-30bf132969bso3086834eec.0 for ; Thu, 25 Jun 2026 05:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782389778; x=1782994578; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nNLU1KKI42jsfktVLjE0+EK3UfxEpxYOmYgYAhnpLzg=; b=ceJ3v2iTRZWdFXPrB3IZMunwhLsMt1Xw4ptuMyRj0APtBFqrhdZWytTM/aQUqZI5TM cTtYGKDLdPDWdJxRtqE4SF25RvYD/rnV9XvCUjHpzlE+wFHem3KdXIBneinSfoaNLfHX yYoF2palrwhuz35scnbTJE3bk6GEXTFiOfBtQUmp7IETLyObNI5kiK7UyXAyNzpn5q4y +vGG0ssx8G6cUMhBqmtNWnBPhDodezSdly11AKBlTNrurnf+hc9wru61Z0+lT1hJpbq/ sbtoy5vxpk4p+xMA9mzWf6D6aDNWFYqMosCfwqctRB+0XmjOmASPytU95GyIYX6sxa/O HHhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782389778; x=1782994578; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nNLU1KKI42jsfktVLjE0+EK3UfxEpxYOmYgYAhnpLzg=; b=q/eqdU7crBVuHGCvwwQ6kh9zABZg/Qfe4L3RGfhIcRw/XTK7IM6EE1e9C1t4iDnM+0 RKs6YV7EFyBzThjUeP3DZnqgKr6u3nXK6d+0nQOWCFjVyxrZb7XMBAVw/WdQxFjSS9lI 1bj65sFmhkSM22G1vIJ7RHbTa3PFK2zDKI5B6V3qt1v2i/k7fZkBGq0B3dXmOE1mzt3n TQtPwuPMRzbUnAoXAD/qqc86TMGjuHE60+osvXwbyMu0DZlOjNLBfn2VRHd41EDkTBF7 pDRdzbaUlWF5bISLmaLnjfv3mcvecz2UZTl4IEDlUbxNUa4QpeDekCYHHUa0lTXAdMK4 GYuw== X-Forwarded-Encrypted: i=1; AHgh+RonA/DGwVTe+SoVW3UjXWJTcQXCbGlmktqn4WXSMTmdI+f5vZDD2g9OQDce/CmLj2O8rGbmBPV3xNpVga8=@vger.kernel.org X-Gm-Message-State: AOJu0YzUOVCq++NxpRLo1R7G365eOigsnrvTjMFwEaixPO2E1NQrkWnH CfBXJU104npCpZVEAqSYwXvJ1ighalhaFc7s7/GROokh3WHhJcpC+1hn X-Gm-Gg: AfdE7clEtoE9gotqHNu+lGtzY04VfE+nXUGNae2ado527Sdjxba+OKvR0dBqZVjDGIN WmQz3aKr+iyitwrP1vhAdz4VkQrFINLOoJUFhy+Fp+ZfOSEIL7kGOh5gqsv2SJOZPMJjT/jXOs0 dVRdk2FnBCuAHdhgBT31ruumJdNxY5Uk+/pEsdG3x5LIuBZIv+b4v2arggLN+sHu220QoSS0Nad 0Mi385vTL/cJvd6sPC3JXKH4A1OPBvN2G2Uar9Tf/uHcO7WnsICW89nBq9G+RefOB90vwG1J4Hd eD5780y5M27kOT4Y8BADz+srF9bBDRQW0J8LeMQYJxvfwRREXs3VyCRRC45PLXxXoiVkXtke8rU ecprlyQHIjcKj4npvGR6ADpyLVcO3NPNAxt69kTlujmRV2zuYXOx/MTJQxWWSBW6R72i0FWjf6L QZY34dIhuq4dJS3IdOj1gBQrCz72FRrMFid2kTyQ== X-Received: by 2002:a05:7301:2a08:b0:307:e4fa:894b with SMTP id 5a478bee46e88-30c84ba3223mr2902960eec.8.1782389778172; Thu, 25 Jun 2026 05:16:18 -0700 (PDT) Received: from hu-ckantibh-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7c8afca8sm7995178eec.17.2026.06.25.05.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 05:16:17 -0700 (PDT) From: Sanjay Chitroda X-Google-Original-From: Sanjay Chitroda To: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@linux.intel.com Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, hongyan.song@intel.com, linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register() Date: Thu, 25 Jun 2026 17:46:11 +0530 Message-Id: <20260625121611.2003780-1-sanjayembedded@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sanjay Chitroda Avoid using devm_iio_device_register(), as this driver requires explicit error handling and teardown ordering. With devm_iio_device_register(), IIO device remains registered until the devres cleanup phase. However, driver's remove() callback removes the sensor hub callback and trigger support. This can create a race window where IIO device is still visible and read_raw() requests are issued. These requests might call sensor_hub_input_attr_get_raw_value(), which waits up to 5 seconds for a response from the sensor hub callback that has already been removed. Add an explicit iio_device_unregister() call in the teardown path to ensure deterministic cleanup, so that userspace can no longer access the device once backend resources begin to be dismantled. Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support") Cc: stable@vger.kernel.org Reviewed-by: Maxwell Doose Reviewed-by: Andy Shevchenko Signed-off-by: Sanjay Chitroda --- Changes in v2: - Added review tags of Maxwell and Andy along with stable Cc - Based on input from Srinivas and investigation use-after-free explanation was not sufficiently justified so updated the commit message with appropriate information and kept Fixes tag - Link to v1: https://lore.kernel.org/all/20260622052135.1804135-1-sanjayembedded@gmail.com --- drivers/iio/temperature/hid-sensor-temperature.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c index a8d3a15f9c53..ab6ec8f659b8 100644 --- a/drivers/iio/temperature/hid-sensor-temperature.c +++ b/drivers/iio/temperature/hid-sensor-temperature.c @@ -244,7 +244,7 @@ static int hid_temperature_probe(struct platform_device *pdev) if (ret) goto error_remove_trigger; - ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); + ret = iio_device_register(indio_dev); if (ret) goto error_remove_callback; @@ -264,6 +264,7 @@ static void hid_temperature_remove(struct platform_device *pdev) struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct temperature_state *temp_st = iio_priv(indio_dev); + iio_device_unregister(indio_dev); sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TEMPERATURE); hid_sensor_remove_trigger(indio_dev, &temp_st->common_attributes); } -- --