Skip to content

Commit 7acc2d9

Browse files
paulmckrcufbq
authored andcommitted
rcutorture: Make cur_ops->format_gp_seqs take buffer length
The Tree and Tiny implementations of rcutorture_format_gp_seqs() use hard-coded constants for the length of the buffer that they format into. This is of course an accident waiting to happen, so this commit therefore makes them take a length argument. The rcutorture calling code uses ARRAY_SIZE() to safely compute this new argument. Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent 65e6ff0 commit 7acc2d9

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

kernel/rcu/rcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ void do_trace_rcu_torture_read(const char *rcutorturename,
591591
static inline void rcu_gp_set_torture_wait(int duration) { }
592592
#endif
593593
unsigned long long rcutorture_gather_gp_seqs(void);
594-
void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp);
594+
void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp, size_t len);
595595

596596
#ifdef CONFIG_TINY_SRCU
597597

kernel/rcu/rcutorture.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ struct rcu_torture_ops {
411411
void (*gp_slow_unregister)(atomic_t *rgssp);
412412
bool (*reader_blocked)(void);
413413
unsigned long long (*gather_gp_seqs)(void);
414-
void (*format_gp_seqs)(unsigned long long seqs, char *cp);
414+
void (*format_gp_seqs)(unsigned long long seqs, char *cp, size_t len);
415415
long cbflood_max;
416416
int irq_capable;
417417
int can_boost;
@@ -3688,8 +3688,10 @@ rcu_torture_cleanup(void)
36883688
char buf2[20+1];
36893689
char sepchar = '-';
36903690

3691-
cur_ops->format_gp_seqs(err_segs[i].rt_gp_seq, buf1);
3692-
cur_ops->format_gp_seqs(err_segs[i].rt_gp_seq_end, buf2);
3691+
cur_ops->format_gp_seqs(err_segs[i].rt_gp_seq,
3692+
buf1, ARRAY_SIZE(buf1));
3693+
cur_ops->format_gp_seqs(err_segs[i].rt_gp_seq_end,
3694+
buf2, ARRAY_SIZE(buf2));
36933695
if (err_segs[i].rt_gp_seq == err_segs[i].rt_gp_seq_end) {
36943696
if (buf2[0]) {
36953697
for (j = 0; buf2[j]; j++)

kernel/rcu/tiny.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ unsigned long long rcutorture_gather_gp_seqs(void)
264264
}
265265
EXPORT_SYMBOL_GPL(rcutorture_gather_gp_seqs);
266266

267-
void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp)
267+
void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp, size_t len)
268268
{
269-
snprintf(cp, 8, "g%04llx", seqs & 0xffffULL);
269+
snprintf(cp, len, "g%04llx", seqs & 0xffffULL);
270270
}
271271
EXPORT_SYMBOL_GPL(rcutorture_format_gp_seqs);
272272
#endif

kernel/rcu/tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,13 @@ unsigned long long rcutorture_gather_gp_seqs(void)
548548
EXPORT_SYMBOL_GPL(rcutorture_gather_gp_seqs);
549549

550550
/* Format grace-period sequence numbers for rcutorture diagnostics. */
551-
void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp)
551+
void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp, size_t len)
552552
{
553553
unsigned int egp = (seqs >> 16) & 0xffffffULL;
554554
unsigned int ggp = (seqs >> 40) & 0xffffULL;
555555
unsigned int pgp = seqs & 0xffffULL;
556556

557-
snprintf(cp, 20, "g%04x:e%06x:p%04x", ggp, egp, pgp);
557+
snprintf(cp, len, "g%04x:e%06x:p%04x", ggp, egp, pgp);
558558
}
559559
EXPORT_SYMBOL_GPL(rcutorture_format_gp_seqs);
560560

0 commit comments

Comments
 (0)