Skip to content

Commit 5c48c21

Browse files
jfischer-nocarlescufi
authored andcommitted
drivers: ssd16xx: derive buffer length from width and height attributes
Derive buffer length from width and height attributes and do not use buf_size direct. Signed-off-by: Johann Fischer <[email protected]>
1 parent f54b106 commit 5c48c21

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/display/ssd16xx.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static int ssd16xx_write(const struct device *dev, const u16_t x,
231231
{
232232
struct ssd16xx_data *driver = dev->driver_data;
233233
int err;
234+
size_t buf_len;
234235
u16_t x_start;
235236
u16_t x_end;
236237
u16_t y_start;
@@ -241,7 +242,8 @@ static int ssd16xx_write(const struct device *dev, const u16_t x,
241242
return -EINVAL;
242243
}
243244

244-
if (buf == NULL || desc->buf_size == 0U) {
245+
buf_len = MIN(desc->buf_size, desc->height * desc->width / 8);
246+
if (buf == NULL || buf_len == 0U) {
245247
LOG_ERR("Display buffer is not available");
246248
return -EINVAL;
247249
}
@@ -311,7 +313,7 @@ static int ssd16xx_write(const struct device *dev, const u16_t x,
311313
}
312314

313315
err = ssd16xx_write_cmd(driver, SSD16XX_CMD_WRITE_RAM, (u8_t *)buf,
314-
desc->buf_size);
316+
buf_len);
315317
if (err < 0) {
316318
return err;
317319
}

0 commit comments

Comments
 (0)