From 10abb160b015841455b0c9d39b3eac709a0a4d36 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 3 Jan 2021 00:37:37 +0000 Subject: [PATCH] scst_vdisk: Fix trailing whitespace removal code in vcdrom_change() Stop looking for trailing whitespace when p == buffer. Remove the local variable 'pp' since it always equals p + 1. Fixes: f381dbb74c84 ("Device sysfs locking reconsidered to remove recently introduced deadlock possibility") git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9311 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index cf0b78c30..eb620613e 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -7664,7 +7664,7 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, char *buffer) { loff_t err; - char *old_fn, *p, *pp; + char *old_fn, *p; bool old_empty; struct file *old_fd; struct file *old_dif_fd; @@ -7688,16 +7688,16 @@ static int vcdrom_change(struct scst_vdisk_dev *virt_dev, p = buffer; + /* Skip leading whitespace */ while (isspace(*p) && *p != '\0') p++; filename = p; + /* Strip trailing whitespace */ + WARN_ON_ONCE(length == 0); p = &buffer[length-1]; - pp = &buffer[length]; - while (isspace(*p) && (*p != '\0')) { - pp = p; + while (p > buffer && isspace(*p)) p--; - } - *pp = '\0'; + p[1] = '\0'; res = scst_suspend_activity(SCST_SUSPEND_TIMEOUT_USER); if (res != 0)