git: 771501e96ffd - main - ses: Add error checking for copyout() calls

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 26 Dec 2023 02:04:22 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=771501e96ffd7e314c338300a351ad76d28a2f69

commit 771501e96ffd7e314c338300a351ad76d28a2f69
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-26 01:40:33 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-26 02:04:00 +0000

    ses: Add error checking for copyout() calls
    
    This is in preparation for annotating copyin() and related functions
    with __result_use_check.
    
    Reviewed by:    mav, imp, asomers
    Tested by:      asomers
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43130
---
 sys/cam/scsi/scsi_enc_ses.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/sys/cam/scsi/scsi_enc_ses.c b/sys/cam/scsi/scsi_enc_ses.c
index 0a3136aa8d10..c429e820a1fd 100644
--- a/sys/cam/scsi/scsi_enc_ses.c
+++ b/sys/cam/scsi/scsi_enc_ses.c
@@ -2810,8 +2810,8 @@ ses_get_elm_desc(enc_softc_t *enc, encioc_elm_desc_t *elmd)
 	}
 	if (elmd->elm_desc_len > elmpriv->descr_len)
 		elmd->elm_desc_len = elmpriv->descr_len;
-	copyout(elmpriv->descr, elmd->elm_desc_str, elmd->elm_desc_len);
-	return (0);
+	return (copyout(elmpriv->descr, elmd->elm_desc_str,
+	    elmd->elm_desc_len));
 }
 
 /**
@@ -2827,7 +2827,7 @@ static int
 ses_get_elm_devnames(enc_softc_t *enc, encioc_elm_devnames_t *elmdn)
 {
 	struct sbuf sb;
-	int len;
+	int error, len;
 
 	len = elmdn->elm_names_size;
 	if (len < 0)
@@ -2839,10 +2839,13 @@ ses_get_elm_devnames(enc_softc_t *enc, encioc_elm_devnames_t *elmdn)
 	    ses_elmdevname_callback, &sb);
 	sbuf_finish(&sb);
 	elmdn->elm_names_len = sbuf_len(&sb);
-	copyout(sbuf_data(&sb), elmdn->elm_devnames, elmdn->elm_names_len + 1);
+	error = copyout(sbuf_data(&sb), elmdn->elm_devnames,
+	    elmdn->elm_names_len + 1);
 	sbuf_delete(&sb);
 	cam_periph_lock(enc->periph);
-	return (elmdn->elm_names_len > 0 ? 0 : ENODEV);
+	if (error == 0 && elmdn->elm_names_len == 0)
+		error = ENODEV;
+	return (error);
 }
 
 /**
@@ -2921,9 +2924,9 @@ ses_handle_string(enc_softc_t *enc, encioc_string_t *sstr, unsigned long ioc)
 		size = rsize;
 		if (size > sstr->bufsiz)
 			size = sstr->bufsiz;
-		copyout(str, sstr->buf, size);
+		ret = copyout(str, sstr->buf, size);
 		sstr->bufsiz = rsize;
-		return (size == rsize ? 0 : ENOMEM);
+		return (ret != 0 ? ret : (size == rsize ? 0 : ENOMEM));
 	case ENCIOC_GETENCID:
 		if (ses_cache->ses_nsubencs < 1)
 			return (ENODEV);
@@ -2935,9 +2938,9 @@ ses_handle_string(enc_softc_t *enc, encioc_string_t *sstr, unsigned long ioc)
 		size = rsize;
 		if (size > sstr->bufsiz)
 			size = sstr->bufsiz;
-		copyout(str, sstr->buf, size);
+		ret = copyout(str, sstr->buf, size);
 		sstr->bufsiz = rsize;
-		return (size == rsize ? 0 : ENOMEM);
+		return (ret != 0 ? ret : (size == rsize ? 0 : ENOMEM));
 	default:
 		return (EINVAL);
 	}