From b151999f06df56da189bec6d8a809ad3b6b3a800 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Thu, 21 Mar 2019 21:18:47 +0800 Subject: [PATCH] blobfs: Add the return value check for calling cache_append_buffer Reason: We need to detect this issue. Otherwise, it will cause null pointer issue later Change-Id: I4d9aec0570e0b46274ebf3b9642b4727049a4a3b Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448594 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- lib/blobfs/blobfs.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index ebd793613..d9422d666 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -2142,19 +2142,19 @@ spdk_file_write(struct spdk_file *file, struct spdk_io_channel *_channel, pthread_spin_lock(&file->lock); file->open_for_writing = true; - if (file->last == NULL) { - if (file->append_pos % CACHE_BUFFER_SIZE == 0) { - cache_append_buffer(file); - } else { - int rc; + if ((file->last == NULL) && (file->append_pos % CACHE_BUFFER_SIZE == 0)) { + cache_append_buffer(file); + } - file->append_pos += length; - pthread_spin_unlock(&file->lock); - rc = __send_rw_from_file(file, &channel->sem, payload, - offset, length, false); - sem_wait(&channel->sem); - return rc; - } + if (file->last == NULL) { + int rc; + + file->append_pos += length; + pthread_spin_unlock(&file->lock); + rc = __send_rw_from_file(file, &channel->sem, payload, + offset, length, false); + sem_wait(&channel->sem); + return rc; } blob_size = __file_get_blob_size(file);