[PATCH v4 1/2] platform/x86: dell-uart-backlight: extract dell_uart_bl_receive_data() helper

From: chitranshmandhaniya

Date: Sat Oct 17 2026 - 03:37:51 EST


From: Chitransh Mandhaniya <Chitransh_Mandhaniya@xxxxxxxx>

Factor the response-byte accumulation and checksum validation out of
dell_uart_bl_receive() into a standalone dell_uart_bl_receive_data()
helper.

The helper returns the number of bytes consumed from the input buffer.
The caller inspects dell_bl->status for the outcome:

-EBUSY frame still incomplete
0 frame received and checksum valid
-EIO checksum mismatch

This is a preparatory refactor for adding stray-byte recovery in the
next patch.

No functional change.

Signed-off-by: Chitransh Mandhaniya <Chitransh_Mandhaniya@xxxxxxxx>
---
.../platform/x86/dell/dell-uart-backlight.c | 42 ++++++++++++-------
1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/dell/dell-uart-backlight.c b/drivers/platform/x86/dell/dell-uart-backlight.c
index f323a667dc2d..5f01ad108338 100644
--- a/drivers/platform/x86/dell/dell-uart-backlight.c
+++ b/drivers/platform/x86/dell/dell-uart-backlight.c
@@ -205,20 +205,13 @@ static const struct backlight_ops dell_uart_backlight_ops = {
.get_brightness = dell_uart_get_brightness_op,
};

-static size_t dell_uart_bl_receive(struct serdev_device *serdev, const u8 *data, size_t len)
+/* Process received UART data; returns number of bytes consumed. */
+static size_t dell_uart_bl_receive_data(struct dell_uart_backlight *dell_bl,
+ const u8 *data, size_t len)
{
- struct dell_uart_backlight *dell_bl = serdev_device_get_drvdata(serdev);
size_t i;
u8 csum;

- dev_dbg(dell_bl->dev, "Recv: %*ph\n", (int)len, data);
-
- /* Throw away unexpected bytes / remainder of response after an error */
- if (dell_bl->status != -EBUSY) {
- dev_warn(dell_bl->dev, "Bytes received out of band, dropping them.\n");
- return len;
- }
-
i = 0;
while (i < len && dell_bl->resp_idx != dell_bl->resp_len) {
dell_bl->resp[dell_bl->resp_idx] = data[i++];
@@ -231,7 +224,7 @@ static size_t dell_uart_bl_receive(struct serdev_device *serdev, const u8 *data,
dev_err(dell_bl->dev, "Response length %d out if range %d - %d\n",
dell_bl->resp_len, MIN_RESP_LEN, dell_bl->resp_max_len);
dell_bl->status = -EIO;
- goto wakeup;
+ return i;
}
break;
case RESP_CMD: /* CMD byte */
@@ -239,7 +232,7 @@ static size_t dell_uart_bl_receive(struct serdev_device *serdev, const u8 *data,
dev_err(dell_bl->dev, "Response cmd 0x%02x != pending 0x%02x\n",
dell_bl->resp[RESP_CMD], dell_bl->pending_cmd);
dell_bl->status = -EIO;
- goto wakeup;
+ return i;
}
break;
}
@@ -247,7 +240,7 @@ static size_t dell_uart_bl_receive(struct serdev_device *serdev, const u8 *data,
}

if (dell_bl->resp_idx != dell_bl->resp_len)
- return len; /* Response not complete yet */
+ return i; /* Response not complete, status stays -EBUSY */

csum = dell_uart_checksum(dell_bl->resp, dell_bl->resp_len - 1);
if (dell_bl->resp[dell_bl->resp_len - 1] == csum) {
@@ -257,11 +250,30 @@ static size_t dell_uart_bl_receive(struct serdev_device *serdev, const u8 *data,
dell_bl->resp[dell_bl->resp_len - 1], csum);
dell_bl->status = -EIO;
}
-wakeup:
- wake_up(&dell_bl->wait_queue);
return i;
}

+static size_t dell_uart_bl_receive(struct serdev_device *serdev, const u8 *data, size_t len)
+{
+ struct dell_uart_backlight *dell_bl = serdev_device_get_drvdata(serdev);
+ size_t ret;
+
+ dev_dbg(dell_bl->dev, "Recv: %*ph\n", (int)len, data);
+
+ /* Throw away unexpected bytes / remainder of response after an error */
+ if (dell_bl->status != -EBUSY) {
+ dev_warn(dell_bl->dev, "Bytes received out of band, dropping them.\n");
+ return len;
+ }
+
+ ret = dell_uart_bl_receive_data(dell_bl, data, len);
+ if (dell_bl->status == -EBUSY)
+ return ret; /* Response not complete yet, waiting for more data */
+
+ wake_up(&dell_bl->wait_queue);
+ return ret;
+}
+
static const struct serdev_device_ops dell_uart_bl_serdev_ops = {
.receive_buf = dell_uart_bl_receive,
.write_wakeup = serdev_device_write_wakeup,
--
2.43.0