Skip to content

Commit

Permalink
hwmon/power8_occ_i2c: Remove 4k stack allocation
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Stanley <joel@jms.id.au>
  • Loading branch information
shenki committed Jan 27, 2016
1 parent fe68a78 commit 087feba
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions drivers/hwmon/power8_occ_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,17 +573,23 @@ static uint8_t occ_send_cmd(struct i2c_client *client, uint8_t seq,

static int occ_get_all(struct i2c_client *client, struct occ_response *occ_resp)
{
uint8_t occ_data[OCC_DATA_MAX];
uint8_t *occ_data;
uint16_t num_bytes;
int i;
int ret;
uint8_t poll_cmd_data;

poll_cmd_data = 0x10;
/*
* TODO: fetch header, and then allocate the rest of the buffer based
* on the header size. Assuming the OCC has a fixed sized header
*/
occ_data = devm_kzalloc(&client->dev, OCC_DATA_MAX, GFP_KERNEL);

ret = occ_send_cmd(client, 0, 0, 1, &poll_cmd_data, occ_data);
if (ret) {
dev_err(&client->dev, "ERROR: OCC Poll: 0x%x\n", ret);
return -1;
ret = -EINVAL;
goto out;
}

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

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

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

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

ret = parse_occ_response(client, occ_data, occ_resp);

out:
devm_kfree(&client->dev, occ_data);
return ret;
}

Expand Down

0 comments on commit 087feba

Please sign in to comment.