Re: [PATCH 2/6] ptrace: introduce ptrace_syscall_enter to consolidate PTRACE_SYSEMU handling

From: Segher Boessenkool
Date: Mon Mar 04 2019 - 07:25:03 EST


On Mon, Mar 04, 2019 at 10:46:43AM +0000, Sudeep Holla wrote:
> On Mon, Mar 04, 2019 at 08:03:47AM +0000, Haibo Xu (Arm Technology China) wrote:
> > On 2019/3/1 2:32, Sudeep Holla wrote:
> > > +long ptrace_syscall_enter(struct pt_regs *regs)
> > > +{
> > > +#ifdef TIF_SYSCALL_EMU
> > > + if (test_thread_flag(TIF_SYSCALL_EMU)) {
> > > + if (tracehook_report_syscall_entry(regs));
> >
> > Shall we remove the semi-colon at end of the above line?
>
> Added intentionally to keep GCC happy.

GCC warns because the user explicitly asked for it, with __must_check.
If you want to do things with an "if" like this, you should write e.g.

if (tracehook_report_syscall_entry(regs))
/*
* We can ignore the return code here, because of
* X and Y and Z.
*/
;

Or it probably is nicer to use a block:

if (tracehook_report_syscall_entry(regs)) {
/*
* We can ignore the return code here, because of
* X and Y and Z.
*/
}

The point is, you *always* should have a nice fat comment if you are
ignoring the return code of a __must_check function.


Segher