use kzalloc for packet buffers; free after sending
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I6a6a696447266c0fad5bef78243a1999a52b0442
This commit is contained in:
parent
1d1d0f96c7
commit
4fa33bab1f
1 changed files with 20 additions and 8 deletions
28
deepcool.c
28
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue