From 4fa33bab1f455c8455abe25b35b72b4ef3dcb674 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 6 Oct 2025 21:56:55 +0300 Subject: [PATCH] use kzalloc for packet buffers; free after sending Signed-off-by: NotAShelf Change-Id: I6a6a696447266c0fad5bef78243a1999a52b0442 --- deepcool.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/deepcool.c b/deepcool.c index 653545f..94ccc77 100644 --- a/deepcool.c +++ b/deepcool.c @@ -343,11 +343,13 @@ static void deepcool_handle_auto_mode(struct deepcool_device *ddata) { // Device communication static int deepcool_send_ak620_pro_packet(struct deepcool_device *ddata) { - u8 data[64] = {0}; + u8 *data = kzalloc(64, GFP_KERNEL); u16 checksum = 0; u16 power, freq; u8 temp; int i, ret; + if (!data) + return -ENOMEM; // Packet header data[0] = 16; @@ -395,7 +397,8 @@ static int deepcool_send_ak620_pro_packet(struct deepcool_device *ddata) { data[19] = 22; // Send HID output report - ret = hid_hw_output_report(ddata->hdev, data, sizeof(data)); + ret = hid_hw_output_report(ddata->hdev, data, 64); + kfree(data); if (ret < 0) { hid_err(ddata->hdev, "Failed to send packet: %d\n", ret); return ret; @@ -405,11 +408,13 @@ static int deepcool_send_ak620_pro_packet(struct deepcool_device *ddata) { } static int deepcool_send_ak_series_packet(struct deepcool_device *ddata) { - u8 data[64] = {0}; + u8 *data = kzalloc(64, GFP_KERNEL); u16 checksum = 0; enum deepcool_mode current_mode; u8 mode_byte; int i, ret; + if (!data) + return -ENOMEM; // Determine current mode if (ddata->mode == MODE_AUTO) { @@ -459,7 +464,8 @@ static int deepcool_send_ak_series_packet(struct deepcool_device *ddata) { data[8] = 22; // Send HID output report - ret = hid_hw_output_report(ddata->hdev, data, sizeof(data)); + ret = hid_hw_output_report(ddata->hdev, data, 64); + kfree(data); if (ret < 0) { hid_err(ddata->hdev, "Failed to send packet: %d\n", ret); return ret; @@ -469,12 +475,14 @@ static int deepcool_send_ak_series_packet(struct deepcool_device *ddata) { } static int deepcool_send_ls_series_packet(struct deepcool_device *ddata) { - u8 data[64] = {0}; + u8 *data = kzalloc(64, GFP_KERNEL); u16 checksum = 0; enum deepcool_mode current_mode; u8 mode_byte; u16 value; int i, ret; + if (!data) + return -ENOMEM; // Determine current mode if (ddata->mode == MODE_AUTO) { @@ -525,7 +533,8 @@ static int deepcool_send_ls_series_packet(struct deepcool_device *ddata) { data[8] = 22; // Send HID output report - ret = hid_hw_output_report(ddata->hdev, data, sizeof(data)); + ret = hid_hw_output_report(ddata->hdev, data, 64); + kfree(data); if (ret < 0) { hid_err(ddata->hdev, "Failed to send packet: %d\n", ret); return ret; @@ -535,11 +544,13 @@ static int deepcool_send_ls_series_packet(struct deepcool_device *ddata) { } static int deepcool_send_ag_series_packet(struct deepcool_device *ddata) { - u8 data[64] = {0}; + u8 *data = kzalloc(64, GFP_KERNEL); u16 checksum = 0; enum deepcool_mode current_mode; u8 mode_byte; int i, ret; + if (!data) + return -ENOMEM; // Determine current mode if (ddata->mode == MODE_AUTO) { @@ -586,7 +597,8 @@ static int deepcool_send_ag_series_packet(struct deepcool_device *ddata) { data[8] = 22; // termination byte // Send HID output report - ret = hid_hw_output_report(ddata->hdev, data, sizeof(data)); + ret = hid_hw_output_report(ddata->hdev, data, 64); + kfree(data); if (ret < 0) { hid_err(ddata->hdev, "Failed to send packet: %d\n", ret); return ret;