[PATCH 16/30] staging: nvec: Have nvec_write_async() return -ENOMEM on OOM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change nvec_write_async() to return an integer, 0 by default,
a negative error on failure. Change nvec_write_sync() to
check the return value and abort if it is negative.

Signed-off-by: Julian Andres Klode <jak@xxxxxxxxxxxxx>
---
 drivers/staging/nvec/nvec.c |   11 +++++++++--
 drivers/staging/nvec/nvec.h |    2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index 75b1d8a..bad3389 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -151,13 +151,16 @@ static void nvec_gpio_set_value(struct nvec_chip *nvec, int value)
 	gpio_set_value(nvec->gpio, value);
 }
 
-void nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
+int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
 			short size)
 {
 	struct nvec_msg *msg;
 	unsigned long flags;
 
 	msg = nvec_msg_alloc(nvec);
+	if (msg == NULL)
+		return -ENOMEM;
+
 	msg->data[0] = size;
 	memcpy(msg->data + 1, data, size);
 	msg->size = size + 1;
@@ -167,6 +170,8 @@ void nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
 	spin_unlock_irqrestore(&nvec->tx_lock, flags);
 
 	queue_work(nvec->wq, &nvec->tx_work);
+
+	return 0;
 }
 EXPORT_SYMBOL(nvec_write_async);
 
@@ -176,7 +181,9 @@ struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
 	mutex_lock(&nvec->sync_write_mutex);
 
 	nvec->sync_write_pending = (data[1] << 8) + data[0];
-	nvec_write_async(nvec, data, size);
+
+	if (nvec_write_async(nvec, data, size) < 0)
+		return NULL;
 
 	dev_dbg(nvec->dev, "nvec_sync_write: 0x%04x\n",
 					nvec->sync_write_pending);
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index 0a98b92..333cb2e 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -97,7 +97,7 @@ struct nvec_chip {
 	int state;
 };
 
-extern void nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
+extern int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
 			     short size);
 
 extern int nvec_register_notifier(struct nvec_chip *nvec,
-- 
1.7.5.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux