Bug 98261 - Misleading indentation in drivers/scsi/bfa/bfa_ioc.c: bfa_cb_sfp_state_query
Summary: Misleading indentation in drivers/scsi/bfa/bfa_ioc.c: bfa_cb_sfp_state_query
Status: NEW
Alias: None
Product: SCSI Drivers
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: scsi_drivers-other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-13 18:26 UTC by Dave Malcolm
Modified: 2016-02-15 22:03 UTC (History)
1 user (show)

See Also:
Kernel Version: 4.0.3
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Dave Malcolm 2015-05-13 18:26:55 UTC
In linux-4.0.3/drivers/scsi/bfa/bfa_ioc.c: bfa_cb_sfp_state_query, the indentation doesn't reflect the actual block structure:

  3659  static void
  3660  bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp)
  3661  {
  3662          bfa_trc(sfp, sfp->portspeed);
  3663          if (sfp->media) {
  3664                  bfa_sfp_media_get(sfp);
  3665                  if (sfp->state_query_cbfn)
  3666                          sfp->state_query_cbfn(sfp->state_query_cbarg,
  3667                                          sfp->status);
  3668                          sfp->media = NULL;
  3669                  }
  3670  
  3671                  if (sfp->portspeed) {
  3672                          sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed);
  3673                          if (sfp->state_query_cbfn)
  3674                                  sfp->state_query_cbfn(sfp->state_query_cbarg,
  3675                                                  sfp->status);
  3676                                  sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
  3677                  }
  3678  
  3679                  sfp->state_query_lock = 0;
  3680                  sfp->state_query_cbfn = NULL;
  3681  }

Note how the "if" at line 3665 does not have an opening brace.  Lines 3666-3668 are indented as if guarded by it, but only lines 3666-3667 are.  The closing brace at line 3669 looks from the indentation as if it relates to line 3665, but it actually relates to line 3663.

Hence although lines 3671 onwards are indented as if guarded by the "if" at line 3663, they are not.

There's also an issue at line 3676, which is indented as if guarded by the "if" at line 3673, but isn't.

Seen via an experimental new gcc warning I'm working on for gcc 6, -Wmisleading-indentation, using gcc r223098 adding -Werror=misleading-indentation" to KBUILD_CFLAGS in Makefile, where the experimental gcc emits these errors:

drivers/scsi/bfa/bfa_ioc.c: In function ‘bfa_cb_sfp_state_query’:
drivers/scsi/bfa/bfa_ioc.c:3668:4: error: statement is indented as if it were guarded by... [-Werror=misleading-indentation]
    sfp->media = NULL;
    ^
drivers/scsi/bfa/bfa_ioc.c:3665:3: note: ...this ‘if’ clause, but it is not
   if (sfp->state_query_cbfn)
   ^
drivers/scsi/bfa/bfa_ioc.c:3676:5: error: statement is indented as if it were guarded by... [-Werror=misleading-indentation]
     sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
     ^
drivers/scsi/bfa/bfa_ioc.c:3673:4: note: ...this ‘if’ clause, but it is not
    if (sfp->state_query_cbfn)
    ^

Note You need to log in before you can comment on or make changes to this bug.