• Xiao Guangrong's avatar
    tracing/function: Fix the return value of ftrace_trace_onoff_callback() · 04aef32d
    Xiao Guangrong authored
    ftrace_trace_onoff_callback() will return an error even if we do the
    right operation, for example:
    
     # echo _spin_*:traceon:10 > set_ftrace_filter
     -bash: echo: write error: Invalid argument
     # cat set_ftrace_filter
     #### all functions enabled ####
     _spin_trylock_bh:traceon:count=10
     _spin_unlock_irq:traceon:count=10
     _spin_unlock_bh:traceon:count=10
     _spin_lock_irq:traceon:count=10
     _spin_unlock:traceon:count=10
     _spin_trylock:traceon:count=10
     _spin_unlock_irqrestore:traceon:count=10
     _spin_lock_irqsave:traceon:count=10
     _spin_lock_bh:traceon:count=10
     _spin_lock:traceon:count=10
    
    We want to set _spin_*:traceon:10 to set_ftrace_filter, it complains
    with "Invalid argument", but the operation is successful.
    
    This is because ftrace_process_regex() returns the number of functions that
    matched the pattern. If the number is not 0, this value is returned
    by ftrace_regex_write() whereas we want to return the number of bytes
    virtually written.
    Also the file offset pointer is not updated in this case.
    
    If the number of matched functions is lower than the number of bytes written
    by the user, this results to a reprocessing of the string given by the user with
    a lower size, leading to a malformed ftrace regex and then a -EINVAL returned.
    
    So, this patch fixes it by returning 0 if no error occured.
    The fix also applies on 2.6.30
    Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
    Reviewed-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
    Cc: stable@kernel.org
    Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
    04aef32d
trace_functions.c 8.22 KB