Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1eeb8067 authored by Ajay Agarwal's avatar Ajay Agarwal
Browse files

usb: f_mtp: Check number of iterations before division



If no MTP transfers have taken place and the user checks
MTP status using
	cat /sys/kernel/debug/usb_mtp/status

Then number of iterations will be 0 and a division by
0 (sum/iteration) would happen in debug_mtp_read_stats
resulting in device crash. Fix this by checking if
num of iterations is >0 and only then division; else 0.

Change-Id: I87ba6daac04d1dfb90409f1a2da15e6659976926
Signed-off-by: default avatarAjay Agarwal <ajaya@codeaurora.org>
parent c97f5cfd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1588,7 +1588,7 @@ static int debug_mtp_read_stats(struct seq_file *s, void *unused)
	}

	seq_printf(s, "vfs_write(time in usec) min:%d\t max:%d\t avg:%d\n",
						min, max, sum / iteration);
				min, max, (iteration ? (sum / iteration) : 0));
	min = max = sum = iteration = 0;
	seq_puts(s, "\n=======================\n");
	seq_puts(s, "MTP Read Stats:\n");
@@ -1610,7 +1610,7 @@ static int debug_mtp_read_stats(struct seq_file *s, void *unused)
	}

	seq_printf(s, "vfs_read(time in usec) min:%d\t max:%d\t avg:%d\n",
						min, max, sum / iteration);
				min, max, (iteration ? (sum / iteration) : 0));
	spin_unlock_irqrestore(&dev->lock, flags);
	return 0;
}