Skip to content

Commit

Permalink
Change the default buffer length according to IEEE 802.15.4. Make sur…
Browse files Browse the repository at this point in the history
…e the buffer's length is bounded during reading and writing.
  • Loading branch information
starnight committed Jul 16, 2017
1 parent 2c82e1e commit 66dcf16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion LoRa/lora.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static LIST_HEAD(device_list);
static DEFINE_MUTEX(device_list_lock);

#ifndef LORA_BUFLEN
#define LORA_BUFLEN 123
#define LORA_BUFLEN 127
#endif

static int
Expand Down
9 changes: 6 additions & 3 deletions LoRa/spi-sx1278.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ sx127X_readLoRaData(struct regmap *rm, uint8_t *buf, size_t len)

/* Get the RX last packet payload length. */
regmap_raw_read(rm, SX127X_REG_RX_NB_BYTES, &blen, 1);

len = (blen < len) ? blen : len;

/* Read LoRa packet payload. */
regmap_raw_read(rm, SX127X_REG_FIFO, buf, len);

Expand Down Expand Up @@ -1060,7 +1060,7 @@ loraspi_read(struct lora_struct *lrdata, const char __user *buf, size_t size)
/* There is a ready packet in the chip's FIFO. */
if (c == 0) {
memset(lrdata->rx_buf, 0, lrdata->bufmaxlen);
size = (lrdata->bufmaxlen < size) ? lrdata->bufmaxlen : size;
size = (lrdata->bufmaxlen <= size) ? lrdata->bufmaxlen : size;
/* Read from chip to LoRa data RX buffer. */
c = sx127X_readLoRaData(rm, lrdata->rx_buf, size);
/* Copy from LoRa data RX buffer to user space. */
Expand Down Expand Up @@ -1101,10 +1101,13 @@ loraspi_write(struct lora_struct *lrdata, const char __user *buf, size_t size)

mutex_lock(&(lrdata->buf_lock));
memset(lrdata->tx_buf, 0, lrdata->bufmaxlen);
size = (lrdata->bufmaxlen < size) ? lrdata->bufmaxlen : size;
status = copy_from_user(lrdata->tx_buf, buf, size);

if (status >= size)
if (status != 0) {
mutex_unlock(&(lrdata->buf_lock));
return 0;
}

lrdata->tx_buflen = size - status;

Expand Down

0 comments on commit 66dcf16

Please sign in to comment.