Skip to content

Commit cb605d4

Browse files
omnijBenjamin Tissoires
authored andcommitted
HID: wacom: use cleanup.h for wacom_wac_queue_flush() buffer management
Use __free(kfree) cleanup facility for the temporary buffer in wacom_wac_queue_flush() to simplify error paths and ensure the buffer is freed automatically when it goes out of scope. Signed-off-by: Jinmo Yang <jinmo44.yang@gmail.com> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
1 parent 55f1ad5 commit cb605d4

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

drivers/hid/wacom_sys.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
7272
{
7373
while (!kfifo_is_empty(fifo)) {
7474
int size = kfifo_peek_len(fifo);
75-
u8 *buf;
75+
u8 *buf __free(kfree) = kzalloc(size, GFP_ATOMIC);
7676
unsigned int count;
7777
int err;
7878

79-
buf = kzalloc(size, GFP_ATOMIC);
8079
if (!buf) {
8180
kfifo_skip(fifo);
8281
continue;
@@ -89,16 +88,13 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
8988
// to flush seems reasonable enough, however.
9089
hid_warn(hdev, "%s: removed fifo entry with unexpected size\n",
9190
__func__);
92-
kfree(buf);
9391
continue;
9492
}
9593
err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, size, false);
9694
if (err) {
9795
hid_warn(hdev, "%s: unable to flush event due to error %d\n",
9896
__func__, err);
9997
}
100-
101-
kfree(buf);
10298
}
10399
}
104100

0 commit comments

Comments
 (0)