fsi: sbefifo: Handle pending write command

If previous write command is still pending then free it first.

As per the current kernel driver design, write operation prepares a
buffer for FSI write, the actual FSI write is performed on next read
operation. There is a possibility of memory leak if buggy application
sends two back to back writes or two parallel writes.

Signed-off-by: Ninad Palsule <ninad@linux.ibm.com>
Reviewed-by: Eddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20231010204348.2600242-3-ninad@linux.ibm.com
Signed-off-by: Joel Stanley <joel@jms.id.au>
This commit is contained in:
Ninad Palsule 2023-10-10 15:43:48 -05:00 committed by Joel Stanley
parent ec084e4ec3
commit f7236a0c91

View File

@ -882,6 +882,13 @@ static ssize_t sbefifo_user_write(struct file *file, const char __user *buf,
mutex_lock(&user->file_lock);
/* If previous write command is still pending then free it. It is safe
* to do that because read cannot be in progress since we hold the
* lock.
*/
if (user->pending_cmd)
sbefifo_release_command(user);
/* Can we use the pre-allocate buffer ? If not, allocate */
if (len <= PAGE_SIZE)
user->pending_cmd = user->cmd_page;