From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 66AEF3E2ACC; Sat, 12 Sep 2026 07:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789197393; cv=none; b=QXTLUQMRdmf/VEtOfJmyeCdzFFd4JeplnvCV3f1hJuha72Dpkvc51tkhSdohc/yOV+ufF6Mo2+ZmlzNmzBNVZ8/jpnK2QYsSQwAarXX/2kqZl2tvx8QjFeS9wqkyOjyz6KcLdU68kY6RP/rWn6DIqKk4gt3DcssJBnypsBiD3ng= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789197393; c=relaxed/simple; bh=12tTcVlsRfbq5iTNAiOoITIS3iOXO0xMxegXgKLn8k0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mqGwsYFZGBPE1w/bCUdVQCkug2QQMLTU3aFqJ5s/eBfvDBPwZoOFrU2FEten/z3hGreMGL5ljeIi4ejYAu0R+bNv5qfXFaalJFKkxVgqC4tNFG/w91MbCs8XxQbclBd/SxacSfs48BIownfWBLrDHbzamh0Co7J6Awp6+dsDmXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TSMFaGU8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TSMFaGU8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AF171F000FF; Sat, 12 Sep 2026 07:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789197392; bh=RROyw5NF4V48O80qtZVm+bzHGm2ndNnH2zt7Yg43WjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TSMFaGU8aMyVBqkNQ61ZkICnIFZLDMuMxhQ7kwP6pAk8oAZnwNgTv2vd1asEinHL/ XoA6cngVx7ZU2K4GeuYUodHCbc7HylkD+BQP+usqnhM6y7l1P1KN52SRANOQPmypwv HnA1+bbMHnsz8B1iyCNFOm/dCZbdOfHG7wlwfVh4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sanjay Chitroda , Andy Shevchenko , Srinivas Pandruvada , Jonathan Cameron , Sasha Levin Subject: [PATCH 7.2 0164/1815] iio: orientation: hid-sensor-rotation: Avoid race between callback setup and device exposure Date: Sat, 12 Sep 2026 08:31:54 +0200 Message-ID: <20260912065652.857400694@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sanjay Chitroda [ Upstream commit 0e32649a7cf3cd784862f8dc0c68a5134731bfff ] The driver currently exposes the IIO device to userspace before completing sensor hub callback registration, and similarly removes callbacks while the device can still be accessed during teardown. This creates a timing window where userspace may enable the buffer before callbacks are available. In such cases: - samples can be dropped, - buffered reads may observe stale or no data. Reorder probe and remove paths to ensure callbacks are active before device exposure and are removed after device is no longer accessible. This avoids a race window leading to data loss. Signed-off-by: Sanjay Chitroda Fixes: fc18dddc0625 ("iio: hid-sensors: Added device rotation support") Reviewed-by: Andy Shevchenko Acked-by: Srinivas Pandruvada Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/orientation/hid-sensor-rotation.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c index cc3e66dbb90fc..f761ec70b4c6c 100644 --- a/drivers/iio/orientation/hid-sensor-rotation.c +++ b/drivers/iio/orientation/hid-sensor-rotation.c @@ -367,12 +367,6 @@ static int hid_dev_rot_probe(struct platform_device *pdev) return ret; } - ret = iio_device_register(indio_dev); - if (ret) { - dev_err(&pdev->dev, "device register failed\n"); - goto error_remove_trigger; - } - rot_state->callbacks.send_event = dev_rot_proc_event; rot_state->callbacks.capture_sample = dev_rot_capture_sample; rot_state->callbacks.pdev = pdev; @@ -380,13 +374,19 @@ static int hid_dev_rot_probe(struct platform_device *pdev) &rot_state->callbacks); if (ret) { dev_err(&pdev->dev, "callback reg failed\n"); - goto error_iio_unreg; + goto error_remove_trigger; + } + + ret = iio_device_register(indio_dev); + if (ret) { + dev_err(&pdev->dev, "device register failed\n"); + goto error_remove_callback; } return 0; -error_iio_unreg: - iio_device_unregister(indio_dev); +error_remove_callback: + sensor_hub_remove_callback(hsdev, hsdev->usage); error_remove_trigger: hid_sensor_remove_trigger(indio_dev, &rot_state->common_attributes); return ret; @@ -399,8 +399,8 @@ static void hid_dev_rot_remove(struct platform_device *pdev) struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct dev_rot_state *rot_state = iio_priv(indio_dev); - sensor_hub_remove_callback(hsdev, hsdev->usage); iio_device_unregister(indio_dev); + sensor_hub_remove_callback(hsdev, hsdev->usage); hid_sensor_remove_trigger(indio_dev, &rot_state->common_attributes); } -- 2.53.0