samples: hw_breakpoint: check the return value of kallsyms_lookup_name
PATCH 1/1 samples: hw_breakpoint: check the return value of kallsyms_lookup_name
data_breakpoint.ko can insert successful but cannot catch any change of the data in my part because kallsyms_lookup_name rerurn 0 each time. So add code to check the return value of kallsyms_lookup_name.
Signed-off-by Hui Zhu <[email protected]>
--- samples/hw_breakpoint/data_breakpoint.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
samples/hw_breakpoint/data_breakpoint.c +10 -7
@@ -52,27 +52,30 @@ static void sample_hbp_handler(struct perf_event *bp,static int __init hw_break_module_init (void ) { -int ret; +int ret =0 ;struct perf_event_attr attr;hw_breakpoint_init (&attr); attr.bp_addr =kallsyms_lookup_name (ksym_name); +if (!attr.bp_addr) { + ret = -ENXIO ; +printk (KERN_INFO "Get address for %s failed\n" , ksym_name); + goto out; + } + attr.bp_len =HW_BREAKPOINT_LEN_4 ; attr.bp_type =HW_BREAKPOINT_W |HW_BREAKPOINT_R ; sample_hbp =register_wide_hw_breakpoint (&attr, sample_hbp_handler,NULL );if (IS_ERR ((void __force *)sample_hbp)) { ret =PTR_ERR ((void __force *)sample_hbp); - goto fail; +printk (KERN_INFO "Breakpoint registration failed\n" ); + goto out; }printk (KERN_INFO "HW Breakpoint for %s write installed\n" , ksym_name); -return 0 ; - -fail: -printk (KERN_INFO "Breakpoint registration failed\n" ); - +out:return ret; }
Signature · 1 line
1.9.1