[PATCH 5/5] scsi: st: factor out the end-of-medium completion test

From: shao.mingyin

Date: Thu Nov 05 2026 - 06:38:16 EST


From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>

The same six-condition EOM test appears twice, once when deciding that
a write-behind finished early and once for the WRITE FILEMARKS path.
Factor it into a helper. The related test in write_behind_check() is
intentionally left alone: it has a different remainder handling and
only uses EOM to turn -EIO into -ENOSPC.

No functional change.

Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index e9d41e3cc2dd..e0ed6b487a20 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -354,6 +354,15 @@ static void st_analyze_sense(struct st_request *SRpnt, struct st_cmdstatus *s)
}


+static bool st_eom_ok(struct st_cmdstatus *cmdstatp)
+{
+ return cmdstatp->have_sense && !cmdstatp->deferred &&
+ (cmdstatp->flags & SENSE_EOM) &&
+ (cmdstatp->sense_hdr.sense_key == NO_SENSE ||
+ cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) &&
+ (!cmdstatp->remainder_valid || cmdstatp->uremainder64 == 0);
+}
+
/* Convert the result to success code */
static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
{
@@ -815,12 +824,7 @@ static int st_flush_write_buffer(struct scsi_tape * STp)
if ((STp->buffer)->syscall_result != 0) {
struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;

- if (cmdstatp->have_sense && !cmdstatp->deferred &&
- (cmdstatp->flags & SENSE_EOM) &&
- (cmdstatp->sense_hdr.sense_key == NO_SENSE ||
- cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) &&
- (!cmdstatp->remainder_valid ||
- cmdstatp->uremainder64 == 0)) { /* All written at EOM early warning */
+ if (st_eom_ok(cmdstatp)) { /* All written at EOM early warning */
STp->dirty = 0;
(STp->buffer)->buffer_bytes = 0;
if (STps->drv_block >= 0)
@@ -1426,11 +1430,7 @@ static int st_flush(struct file *filp, fl_owner_t id)
}

if (STp->buffer->syscall_result == 0 ||
- (cmdstatp->have_sense && !cmdstatp->deferred &&
- (cmdstatp->flags & SENSE_EOM) &&
- (cmdstatp->sense_hdr.sense_key == NO_SENSE ||
- cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) &&
- (!cmdstatp->remainder_valid || cmdstatp->uremainder64 == 0))) {
+ st_eom_ok(cmdstatp)) {
/* Write successful at EOM */
st_release_request(SRpnt);
SRpnt = NULL;