serial: Fix unused result warning for write()

serial.c: In function ‘mctp_binding_serial_tx’:
serial.c:145:3: warning: ignoring return value of ‘write’, declared with
attribute warn_unused_result [-Wunused-result]
  145 |   write(serial->fd, serial->txbuf, len);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CCLD     libmctp.la

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ie85426ee2c33bc11f730a9ce66a5c6c7c841b920
diff --git a/serial.c b/serial.c
index ce4ea91..d59bf44 100644
--- a/serial.c
+++ b/serial.c
@@ -21,6 +21,19 @@
 
 #define pr_fmt(x) "serial: " x
 
+/* Post-condition: All bytes written or an error has occurred */
+#define mctp_write_all(fn, dst, src, len)				\
+({									\
+	ssize_t wrote;							\
+	while (len) {							\
+		wrote = fn(dst, src, len);				\
+		if (wrote < 0)						\
+			break;						\
+		len -= wrote;						\
+	}								\
+	len ? -1 : 0;							\
+})
+
 #include "libmctp.h"
 #include "libmctp-alloc.h"
 #include "libmctp-log.h"
@@ -139,12 +152,11 @@
 
 	len += sizeof(*hdr) + sizeof(*tlr);
 
-	if (serial->tx_fn)
-		serial->tx_fn(serial->tx_fn_data, serial->txbuf, len);
-	else
-		write(serial->fd, serial->txbuf, len);
+	if (!serial->tx_fn)
+		return mctp_write_all(write, serial->fd, serial->txbuf, len);
 
-	return 0;
+	return mctp_write_all(serial->tx_fn, serial->tx_fn_data, serial->txbuf,
+			      len);
 }
 
 static void mctp_serial_finish_packet(struct mctp_binding_serial *serial,