Skip to content

Commit 087feba

Browse files
committed
hwmon/power8_occ_i2c: Remove 4k stack allocation
Signed-off-by: Joel Stanley <joel@jms.id.au>
1 parent fe68a78 commit 087feba

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/hwmon/power8_occ_i2c.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,17 +573,23 @@ static uint8_t occ_send_cmd(struct i2c_client *client, uint8_t seq,
573573

574574
static int occ_get_all(struct i2c_client *client, struct occ_response *occ_resp)
575575
{
576-
uint8_t occ_data[OCC_DATA_MAX];
576+
uint8_t *occ_data;
577577
uint16_t num_bytes;
578578
int i;
579579
int ret;
580580
uint8_t poll_cmd_data;
581581

582-
poll_cmd_data = 0x10;
582+
/*
583+
* TODO: fetch header, and then allocate the rest of the buffer based
584+
* on the header size. Assuming the OCC has a fixed sized header
585+
*/
586+
occ_data = devm_kzalloc(&client->dev, OCC_DATA_MAX, GFP_KERNEL);
587+
583588
ret = occ_send_cmd(client, 0, 0, 1, &poll_cmd_data, occ_data);
584589
if (ret) {
585590
dev_err(&client->dev, "ERROR: OCC Poll: 0x%x\n", ret);
586-
return -1;
591+
ret = -EINVAL;
592+
goto out;
587593
}
588594

589595
num_bytes = get_occdata_length(occ_data);
@@ -592,12 +598,14 @@ static int occ_get_all(struct i2c_client *client, struct occ_response *occ_resp)
592598

593599
if (num_bytes > OCC_DATA_MAX) {
594600
dev_err(&client->dev, "ERROR: OCC data length must be < 4KB\n");
595-
return -1;
601+
ret = -EINVAL;
602+
goto out;
596603
}
597604

598605
if (num_bytes <= 0) {
599606
dev_err(&client->dev, "ERROR: OCC data length is zero\n");
600-
return -1;
607+
ret = -EINVAL;
608+
goto out;
601609
}
602610

603611
/* read remaining data */
@@ -606,6 +614,8 @@ static int occ_get_all(struct i2c_client *client, struct occ_response *occ_resp)
606614

607615
ret = parse_occ_response(client, occ_data, occ_resp);
608616

617+
out:
618+
devm_kfree(&client->dev, occ_data);
609619
return ret;
610620
}
611621

0 commit comments

Comments
 (0)