Commit 78cba163 authored by Li Nan's avatar Li Nan Committed by Jialin Zhang
Browse files

block: Only set bb->changed when badblocks changes

hulk inclusion
category: bugfix
bugzilla: 188569, https://gitee.com/openeuler/kernel/issues/I6XBZQ


CVE: NA

--------------------------------

bb->changed and unacked_exist is set and badblocks_update_acked() is
involked even if no badblocks changes in badblocks_set(). Only update
them when badblocks changes.

Fixes: 9e0e252a ("badblocks: Add core badblock management code")
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
Reviewed-by: default avatarYu Kuai <yukuai3@huawei.com>
Reviewed-by: default avatarHou Tao <houtao1@huawei.com>
parent 7b3b8187
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
{
	u64 *p;
	int lo, hi;
	int rv = 0;
	int rv = 0, changed = 0;
	unsigned long flags;

	if (bb->shift < 0)
@@ -230,6 +230,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
				s = a + BB_MAX_LEN;
			}
			sectors = e - s;
			changed = 1;
		}
	}
	if (sectors && hi < bb->count) {
@@ -260,6 +261,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
			sectors = e - s;
			lo = hi;
			hi++;
			changed = 1;
		}
	}
	if (sectors == 0 && hi < bb->count) {
@@ -278,6 +280,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
			memmove(p + hi, p + hi + 1,
				(bb->count - hi - 1) * 8);
			bb->count--;
			changed = 1;
		}
	}
	while (sectors) {
@@ -300,14 +303,17 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
			p[hi] = BB_MAKE(s, this_sectors, acknowledged);
			sectors -= this_sectors;
			s += this_sectors;
			changed = 1;
		}
	}

	bb->changed = 1;
	if (changed) {
		bb->changed = changed;
		if (!acknowledged)
			bb->unacked_exist = 1;
		else
			badblocks_update_acked(bb);
	}
	write_sequnlock_irqrestore(&bb->lock, flags);

	return rv;