-1

I am getting MISRA C:2012 Rule-17.7 violation for below code. I am quite new to C code and MISRA concepts. Any suggestions would be greatly appreciated.

 5277:   Dem_SetEventStatus(Rte_PDAV_DemEvent_DtcC00100_1, EventStatus);
         ^
Msg(7:3200) 'Dem_SetEventStatus' returns a value which is not being used.
MISRA C:2012 Rule-17.7
chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • 9
    What part of "*returns a value which is not being used*" do you not understand? The function is returning something but this line of code throws away that return value. – kaylum Dec 11 '21 at 05:42
  • 3
    In addition to running a MISRA checker you should get your own copy of MISRA spec. There you can read more details of any rule. The issue in your question is very clear. But some messages from MISRA checkers are more cryptic or even completely crap compared to what the cited rule really is about. – Gerhardh Dec 11 '21 at 09:02

2 Answers2

7

Background
The Diagnostic Event Manager (Dem) is a Basic Software Module of the AUTOSAR Diagnostic Services. Relevant errors are reported either from Application Layer (resp. SW-C) or Basic Software Modules (BSWM).

  • BSWs report the new status of the event with the Dem_ReportErrorStatus API
  • SWCs report the new status of the event with the Dem_SetEventStatus API (through the RTE)

The Diagnostic Event Manager (Dem) handles and stores the diagnostic events detected by diagnostic monitors in both Software Components (SW-Cs) and Basic Software Modules (BSWM). The stored event information is available via an interface to other BSW modules or SW-Cs.

Function Dem_SetEventStatus()
This function has a prototype of:

Std_ReturnType Dem_SetEventStatus(
Dem_EventIdType EventId,
Dem_EventStatusType EventStatus
)

Note the return type is Std_ReturnType - which returns either E_OK or E_NOT_OK

MISRA C:2012 Rule 17.7
MISRA C:2012 Rule 17.7 requires that you do something with the values returned from a (non-void) function...

The function is telling you something... it has either succeeded E_OK or failed E_NOT_OK - ignoring this information is probably not a good idea.

If you genuinely want to ignore it, then stick in a (void) cast - but make sure you add a good clear rationale for doing so.

See profile for affiliation

Andrew
  • 2,046
  • 1
  • 24
  • 37
  • 1
    Just as a hint, since AR 4.3, the `Dem_ReportErrorStatus()` function is obsolete, and also BSW modules shall use `Dem_SetEventStatus()`. The Dem can deternine between BSW and SWCs due to the configuration of the DemEvent and its parameter `DemEventKind`. – kesselhaus Dec 12 '21 at 17:37
0

Dem_SetEventStatus is returning a standard return type with some values (e.g., EOK and E_NOT_OK)

If the API was successful in doing what it was supposed to do then you will get E_OK and if some error pops up then you get E_NOK

With an indication of error, you may want to retry setting the event or just ignore depending on your strategy to handle the functionality.

Andrew
  • 2,046
  • 1
  • 24
  • 37
vpush
  • 11
  • 1