Skip to content

Commit

Permalink
module: Fix required MISRA defects rule 10.3
Browse files Browse the repository at this point in the history
MISRA 10.3 defects relating to module files will be addressed
in this patch.

The 10.3 rule states "the value of an expression shall not be assigned
to an object with a narrower essential type or of a different essential
type category".

Signed-off-by: Katherine Vincent <[email protected]>
Change-Id: I106e322999148ef6832d292d2a96843ffeab76b0
  • Loading branch information
katvin01 authored and nicola-mazzucato-arm committed Jun 9, 2021
1 parent 057eb9a commit 2b42199
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 104 deletions.
25 changes: 13 additions & 12 deletions module/clock/src/mod_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,8 @@ static int clock_process_notification_response(
* that is pending.
*/
if (resp_params->status != FWK_SUCCESS) {
ctx->pd_notif.transition_pending_response_status = resp_params->status;
ctx->pd_notif.transition_pending_response_status =
(unsigned int)resp_params->status;
}

if ((--(ctx->pd_notif.transition_pending_sent)) == 0) {
Expand All @@ -654,7 +655,7 @@ static int clock_process_notification_response(
(struct mod_pd_power_state_pre_transition_notification_resp_params
*)pd_response_event.params;
pd_resp_params->status =
ctx->pd_notif.transition_pending_response_status;
(int)ctx->pd_notif.transition_pending_response_status;
fwk_thread_put_event(&pd_response_event);
}

Expand Down Expand Up @@ -699,21 +700,21 @@ static int clock_process_event(const struct fwk_event *event,
}

switch (fwk_id_get_event_idx(event->id)) {
case MOD_CLOCK_EVENT_IDX_SET_RATE_REQUEST:
case MOD_CLOCK_EVENT_IDX_GET_RATE_REQUEST:
case MOD_CLOCK_EVENT_IDX_SET_STATE_REQUEST:
case MOD_CLOCK_EVENT_IDX_GET_STATE_REQUEST:
case (unsigned int)MOD_CLOCK_EVENT_IDX_SET_RATE_REQUEST:
case (unsigned int)MOD_CLOCK_EVENT_IDX_GET_RATE_REQUEST:
case (unsigned int)MOD_CLOCK_EVENT_IDX_SET_STATE_REQUEST:
case (unsigned int)MOD_CLOCK_EVENT_IDX_GET_STATE_REQUEST:
return process_request_event(event, resp_event);

#ifdef BUILD_HAS_CLOCK_TREE_MGMT
case CLOCK_EVENT_IDX_SET_STATE_PRE_REQUEST:
case (unsigned int)CLOCK_EVENT_IDX_SET_STATE_PRE_REQUEST:
return clock_management_process_state(event);

case CLOCK_EVENT_IDX_SET_RATE_PRE_REQUEST:
case (unsigned int)CLOCK_EVENT_IDX_SET_RATE_PRE_REQUEST:
return clock_management_process_rate(event);
#endif

case CLOCK_EVENT_IDX_RESPONSE:
case (unsigned int)CLOCK_EVENT_IDX_RESPONSE:
return process_response_event(event);

default:
Expand All @@ -724,9 +725,9 @@ static int clock_process_event(const struct fwk_event *event,
const struct fwk_module module_clock = {
.name = "Clock HAL",
.type = FWK_MODULE_TYPE_HAL,
.api_count = MOD_CLOCK_API_COUNT,
.event_count = CLOCK_EVENT_IDX_COUNT,
.notification_count = MOD_CLOCK_NOTIFICATION_IDX_COUNT,
.api_count = (unsigned int)MOD_CLOCK_API_COUNT,
.event_count = (unsigned int)CLOCK_EVENT_IDX_COUNT,
.notification_count = (unsigned int)MOD_CLOCK_NOTIFICATION_IDX_COUNT,
.init = clock_init,
.element_init = clock_dev_init,
.bind = clock_bind,
Expand Down
6 changes: 3 additions & 3 deletions module/dvfs/src/mod_dvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ static int dvfs_element_init(
fwk_assert(ctx->config->opps != NULL);

/* Initialize the context */
ctx->opp_count = count_opps(ctx->config->opps);
ctx->opp_count = (size_t)count_opps(ctx->config->opps);
fwk_assert(ctx->opp_count > 0);

/* Level limits default to the minimum and maximum available */
Expand Down Expand Up @@ -1389,6 +1389,6 @@ const struct fwk_module module_dvfs = {
.process_bind_request = dvfs_process_bind_request,
.process_event = mod_dvfs_process_event,
.process_signal = mod_dvfs_process_signal,
.api_count = MOD_DVFS_API_IDX_COUNT,
.event_count = MOD_DVFS_INTERNAL_EVENT_IDX_COUNT,
.api_count = (unsigned int)MOD_DVFS_API_IDX_COUNT,
.event_count = (unsigned int)MOD_DVFS_INTERNAL_EVENT_IDX_COUNT,
};
2 changes: 1 addition & 1 deletion module/dw_apb_i2c/src/mod_dw_apb_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static int dw_apb_i2c_start(fwk_id_t id)

const struct fwk_module module_dw_apb_i2c = {
.name = "DW APB I2C",
.api_count = MOD_DW_APB_I2C_API_IDX_COUNT,
.api_count = (unsigned int)MOD_DW_APB_I2C_API_IDX_COUNT,
.type = FWK_MODULE_TYPE_DRIVER,
.init = dw_apb_i2c_init,
.element_init = dw_apb_i2c_element_init,
Expand Down
4 changes: 2 additions & 2 deletions module/gtimer/src/mod_gtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ static int set_timer(fwk_id_t dev_id, uint64_t timestamp)

ctx = mod_gtimer_ctx.table + fwk_id_get_element_idx(dev_id);

ctx->hw_timer->P_CVALL = timestamp & 0xFFFFFFFF;
ctx->hw_timer->P_CVALH = timestamp >> 32;
ctx->hw_timer->P_CVALL = (uint32_t)(timestamp & 0xFFFFFFFFUL);
ctx->hw_timer->P_CVALH = (uint32_t)(timestamp >> 32UL);

return FWK_SUCCESS;
}
Expand Down
11 changes: 7 additions & 4 deletions module/i2c/src/mod_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static int process_request(struct mod_i2c_dev_ctx *ctx, fwk_id_t event_id)
const struct mod_i2c_driver_api *driver_api = ctx->driver_api;
fwk_id_t driver_id = ctx->config->driver_id;

switch (fwk_id_get_event_idx(event_id)) {
switch ((enum mod_i2c_event_idx)fwk_id_get_event_idx(event_id)) {
case MOD_I2C_EVENT_IDX_REQUEST_TRANSMIT:
ctx->state = MOD_I2C_DEV_TX;
drv_status = driver_api->transmit_as_master(driver_id, &ctx->request);
Expand All @@ -334,6 +334,9 @@ static int process_request(struct mod_i2c_dev_ctx *ctx, fwk_id_t event_id)
ctx->state = MOD_I2C_DEV_RX;
drv_status = driver_api->receive_as_master(driver_id, &ctx->request);
break;

default:
break;
}

return drv_status;
Expand Down Expand Up @@ -451,7 +454,7 @@ static int mod_i2c_process_event(const struct fwk_event *event,
return FWK_SUCCESS;
}

switch (fwk_id_get_event_idx(event->id)) {
switch ((enum mod_i2c_internal_event_idx)fwk_id_get_event_idx(event->id)) {
case MOD_I2C_EVENT_IDX_REQUEST_COMPLETED:
event_param = (struct mod_i2c_event_param *)event->params;

Expand Down Expand Up @@ -507,8 +510,8 @@ static int mod_i2c_process_event(const struct fwk_event *event,
const struct fwk_module module_i2c = {
.name = "I2C",
.type = FWK_MODULE_TYPE_HAL,
.api_count = MOD_I2C_API_IDX_COUNT,
.event_count = MOD_I2C_EVENT_IDX_TOTAL_COUNT,
.api_count = (unsigned int)MOD_I2C_API_IDX_COUNT,
.event_count = (unsigned int)MOD_I2C_EVENT_IDX_TOTAL_COUNT,
.init = mod_i2c_init,
.element_init = mod_i2c_dev_init,
.bind = mod_i2c_bind,
Expand Down
2 changes: 1 addition & 1 deletion module/mhu/src/mod_mhu.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void mhu_isr(void)

/* Loop over all the slots */
while (reg->STAT != 0) {
slot = __builtin_ctz(reg->STAT);
slot = (unsigned int)__builtin_ctz(reg->STAT);

/*
* If the slot is bound to an SMT channel, signal the message to the
Expand Down
5 changes: 3 additions & 2 deletions module/mock_clock/src/mod_mock_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ static int mod_mock_clock_set_rate(
return FWK_E_PARAM;
}

ctx->current_rate_index = rate_entry - ctx->config->rate_table;
ctx->current_rate_index =
(unsigned int)(rate_entry - ctx->config->rate_table);

ctx->rate_initialized = true;

Expand Down Expand Up @@ -310,6 +311,6 @@ const struct fwk_module module_mock_clock = {
.init = mod_mock_clock_init,
.element_init = mod_mock_clock_element_init,

.api_count = MOD_MOCK_CLOCK_API_COUNT,
.api_count = (unsigned int)MOD_MOCK_CLOCK_API_COUNT,
.process_bind_request = mod_mock_clock_process_bind_request,
};
2 changes: 1 addition & 1 deletion module/mock_psu/src/mod_mock_psu.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,6 @@ const struct fwk_module module_mock_psu = {
.element_init = mod_mock_psu_element_init,
.bind = mod_mock_psu_bind,

.api_count = MOD_MOCK_PSU_API_IDX_COUNT,
.api_count = (unsigned int)MOD_MOCK_PSU_API_IDX_COUNT,
.process_bind_request = mod_mock_psu_process_bind_request,
};
26 changes: 13 additions & 13 deletions module/pl011/src/mod_pl011.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int mod_pl011_init_ctx(struct mod_pl011_ctx *ctx)

fwk_assert(!mod_pl011_ctx.initialized);

element_count = fwk_module_get_element_count(fwk_module_id_pl011);
element_count = (size_t)fwk_module_get_element_count(fwk_module_id_pl011);
if (element_count == 0) {
return FWK_SUCCESS;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ static void mod_pl011_set_baud_rate(const struct mod_pl011_element_cfg *cfg)
fwk_assert((PL011_UARTCLK_MAX * UINT64_C(4)) < UINT32_MAX);

/* Ensure baud rate is not higher than the clock can support */
clock_rate_x4 = cfg->clock_rate_hz * 4;
clock_rate_x4 = (uint32_t)(cfg->clock_rate_hz * 4);
fwk_assert(cfg->baud_rate_bps <= clock_rate_x4);

/* Calculate integer and fractional divisors */
Expand All @@ -136,7 +136,7 @@ static void mod_pl011_set_baud_rate(const struct mod_pl011_element_cfg *cfg)
*/
fwk_assert((divisor_integer == 0xFFFF) == (divisor_fractional == 0));

reg->IBRD = divisor_integer;
reg->IBRD = (uint16_t)divisor_integer;
reg->FBRD = divisor_fractional;
}

Expand Down Expand Up @@ -173,7 +173,7 @@ static void mod_pl011_putch(fwk_id_t id, char ch)
continue;
}

reg->DR = ch;
reg->DR = (uint16_t)ch;
}

static bool mod_pl011_getch(fwk_id_t id, char *ch)
Expand All @@ -191,7 +191,7 @@ static bool mod_pl011_getch(fwk_id_t id, char *ch)
return false;
}

*ch = reg->DR;
*ch = (char)reg->DR;

return true;
}
Expand Down Expand Up @@ -351,7 +351,7 @@ static int mod_pl011_process_power_notification(
int status = FWK_SUCCESS;

switch (fwk_id_get_notification_idx(event->id)) {
case MOD_PD_NOTIFICATION_IDX_POWER_STATE_PRE_TRANSITION: {
case (unsigned int)MOD_PD_NOTIFICATION_IDX_POWER_STATE_PRE_TRANSITION: {
struct mod_pd_power_state_pre_transition_notification_params
*pd_pre_transition_params;
struct mod_pd_power_state_pre_transition_notification_resp_params
Expand All @@ -366,11 +366,11 @@ static int mod_pl011_process_power_notification(

switch (pd_pre_transition_params->target_state) {
# ifdef BUILD_HAS_MOD_SYSTEM_POWER
case MOD_SYSTEM_POWER_POWER_STATE_SLEEP0:
case (unsigned int)MOD_SYSTEM_POWER_POWER_STATE_SLEEP0:
FWK_FALLTHROUGH;
# endif

case MOD_PD_STATE_OFF:
case (unsigned int)MOD_PD_STATE_OFF:
status = mod_pl011_powering_down(event->target_id);

pd_resp_params->status = status; /* Inform the power domain */
Expand All @@ -384,7 +384,7 @@ static int mod_pl011_process_power_notification(
break;
}

case MOD_PD_NOTIFICATION_IDX_POWER_STATE_TRANSITION: {
case (unsigned int)MOD_PD_NOTIFICATION_IDX_POWER_STATE_TRANSITION: {
struct mod_pd_power_state_transition_notification_params *params =
(struct mod_pd_power_state_transition_notification_params *)
event->params;
Expand All @@ -398,7 +398,7 @@ static int mod_pl011_process_power_notification(
break;
}

case MOD_PD_NOTIFICATION_IDX_PRE_SHUTDOWN: {
case (unsigned int)MOD_PD_NOTIFICATION_IDX_PRE_SHUTDOWN: {
struct mod_pd_pre_shutdown_notif_resp_params
*pd_pre_shutdown_resp_params =
(struct mod_pd_pre_shutdown_notif_resp_params *)
Expand Down Expand Up @@ -508,12 +508,12 @@ static int mod_pl011_process_clock_notification(
int status = FWK_SUCCESS;

switch (fwk_id_get_notification_idx(event->id)) {
case MOD_CLOCK_NOTIFICATION_IDX_STATE_CHANGED:
case (unsigned int)MOD_CLOCK_NOTIFICATION_IDX_STATE_CHANGED:
status = mod_pl011_clock_changed(event);

break;

case MOD_CLOCK_NOTIFICATION_IDX_STATE_CHANGE_PENDING:
case (unsigned int)MOD_CLOCK_NOTIFICATION_IDX_STATE_CHANGE_PENDING:
status = mod_pl011_clock_change_pending(event, resp_event);

break;
Expand All @@ -533,7 +533,7 @@ static int mod_pl011_process_notification(

fwk_assert(fwk_id_is_type(event->target_id, FWK_ID_TYPE_ELEMENT));

module_idx = fwk_id_get_module_idx(event->id);
module_idx = (enum fwk_module_idx)fwk_id_get_module_idx(event->id);

switch (module_idx) {
#ifdef BUILD_HAS_MOD_POWER_DOMAIN
Expand Down
Loading

0 comments on commit 2b42199

Please sign in to comment.