@@ -289,6 +289,10 @@ static struct hist_field *find_var(struct hist_trigger_data *hist_data,
289
289
return NULL ;
290
290
}
291
291
292
+ struct hist_elt_data {
293
+ char * comm ;
294
+ };
295
+
292
296
static const char * hist_field_name (struct hist_field * field ,
293
297
unsigned int level )
294
298
{
@@ -503,45 +507,61 @@ static inline void save_comm(char *comm, struct task_struct *task)
503
507
memcpy (comm , task -> comm , TASK_COMM_LEN );
504
508
}
505
509
506
- static void hist_trigger_elt_comm_free (struct tracing_map_elt * elt )
510
+ static void hist_elt_data_free (struct hist_elt_data * elt_data )
511
+ {
512
+ kfree (elt_data -> comm );
513
+ kfree (elt_data );
514
+ }
515
+
516
+ static void hist_trigger_elt_data_free (struct tracing_map_elt * elt )
507
517
{
508
- kfree ((char * )elt -> private_data );
518
+ struct hist_elt_data * elt_data = elt -> private_data ;
519
+
520
+ hist_elt_data_free (elt_data );
509
521
}
510
522
511
- static int hist_trigger_elt_comm_alloc (struct tracing_map_elt * elt )
523
+ static int hist_trigger_elt_data_alloc (struct tracing_map_elt * elt )
512
524
{
513
525
struct hist_trigger_data * hist_data = elt -> map -> private_data ;
526
+ unsigned int size = TASK_COMM_LEN ;
527
+ struct hist_elt_data * elt_data ;
514
528
struct hist_field * key_field ;
515
529
unsigned int i ;
516
530
531
+ elt_data = kzalloc (sizeof (* elt_data ), GFP_KERNEL );
532
+ if (!elt_data )
533
+ return - ENOMEM ;
534
+
517
535
for_each_hist_key_field (i , hist_data ) {
518
536
key_field = hist_data -> fields [i ];
519
537
520
538
if (key_field -> flags & HIST_FIELD_FL_EXECNAME ) {
521
- unsigned int size = TASK_COMM_LEN + 1 ;
522
-
523
- elt -> private_data = kzalloc (size , GFP_KERNEL );
524
- if (!elt -> private_data )
539
+ elt_data -> comm = kzalloc (size , GFP_KERNEL );
540
+ if (!elt_data -> comm ) {
541
+ kfree (elt_data );
525
542
return - ENOMEM ;
543
+ }
526
544
break ;
527
545
}
528
546
}
529
547
548
+ elt -> private_data = elt_data ;
549
+
530
550
return 0 ;
531
551
}
532
552
533
- static void hist_trigger_elt_comm_init (struct tracing_map_elt * elt )
553
+ static void hist_trigger_elt_data_init (struct tracing_map_elt * elt )
534
554
{
535
- char * comm = elt -> private_data ;
555
+ struct hist_elt_data * elt_data = elt -> private_data ;
536
556
537
- if (comm )
538
- save_comm (comm , current );
557
+ if (elt_data -> comm )
558
+ save_comm (elt_data -> comm , current );
539
559
}
540
560
541
- static const struct tracing_map_ops hist_trigger_elt_comm_ops = {
542
- .elt_alloc = hist_trigger_elt_comm_alloc ,
543
- .elt_free = hist_trigger_elt_comm_free ,
544
- .elt_init = hist_trigger_elt_comm_init ,
561
+ static const struct tracing_map_ops hist_trigger_elt_data_ops = {
562
+ .elt_alloc = hist_trigger_elt_data_alloc ,
563
+ .elt_free = hist_trigger_elt_data_free ,
564
+ .elt_init = hist_trigger_elt_data_init ,
545
565
};
546
566
547
567
static const char * get_hist_field_flags (struct hist_field * hist_field )
@@ -1484,21 +1504,6 @@ static int create_tracing_map_fields(struct hist_trigger_data *hist_data)
1484
1504
return 0 ;
1485
1505
}
1486
1506
1487
- static bool need_tracing_map_ops (struct hist_trigger_data * hist_data )
1488
- {
1489
- struct hist_field * key_field ;
1490
- unsigned int i ;
1491
-
1492
- for_each_hist_key_field (i , hist_data ) {
1493
- key_field = hist_data -> fields [i ];
1494
-
1495
- if (key_field -> flags & HIST_FIELD_FL_EXECNAME )
1496
- return true;
1497
- }
1498
-
1499
- return false;
1500
- }
1501
-
1502
1507
static struct hist_trigger_data *
1503
1508
create_hist_data (unsigned int map_bits ,
1504
1509
struct hist_trigger_attrs * attrs ,
@@ -1524,8 +1529,7 @@ create_hist_data(unsigned int map_bits,
1524
1529
if (ret )
1525
1530
goto free ;
1526
1531
1527
- if (need_tracing_map_ops (hist_data ))
1528
- map_ops = & hist_trigger_elt_comm_ops ;
1532
+ map_ops = & hist_trigger_elt_data_ops ;
1529
1533
1530
1534
hist_data -> map = tracing_map_create (map_bits , hist_data -> key_size ,
1531
1535
map_ops , hist_data );
@@ -1713,7 +1717,13 @@ hist_trigger_entry_print(struct seq_file *m,
1713
1717
seq_printf (m , "%s: [%llx] %-55s" , field_name ,
1714
1718
uval , str );
1715
1719
} else if (key_field -> flags & HIST_FIELD_FL_EXECNAME ) {
1716
- char * comm = elt -> private_data ;
1720
+ struct hist_elt_data * elt_data = elt -> private_data ;
1721
+ char * comm ;
1722
+
1723
+ if (WARN_ON_ONCE (!elt_data ))
1724
+ return ;
1725
+
1726
+ comm = elt_data -> comm ;
1717
1727
1718
1728
uval = * (u64 * )(key + key_field -> offset );
1719
1729
seq_printf (m , "%s: %-16s[%10llu]" , field_name ,
0 commit comments