gpu: nvgpu: container_of() changes to sema code

The container_of() macro used in nvgpu produces the following
set of MISRA required rule violations:

 * Rule 11.3 : A cast shall not be performed between a pointer to
               object type and a pointer to a different object type.
 * Rule 11.8 : A cast shall not remove any const or volatile
               qualification from the type pointed to be a pointer.
 * Rule 20.7 : Expressions resulting from the expansion of macro
               parameters shall be enclosed in parentheses.

Using the same modified implementation of container_of() as that
used in the nvgpu_list_node/nvgpu_rbtree_node routines eliminates
the Rule 11.8 and Rule 20.7 violations and exchanges the Rule 11.3
violation with an advisory Rule 11.4 violation.

This patch uses that same equivalent implementation in two new
(static) functions that are used to replace the references to
container_of() in common semaphore code:

 * nvgpu_semaphore_pool_from_ref
 * nvgpu_semaphore_from_ref

It should be noted that replacement functions still contain
potentially dangerous (and non-MISRA compliant code) and that it is
expected that deviation requests will be filed for the new advisory
rule violations accordingly.

JIRA NVGPU-782

Change-Id: I79c0b6fc4fa819c92985f2e2239e9d1d7137618d
Signed-off-by: Scott Long <scottl@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1995937
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Scott Long
2019-01-15 14:59:44 -08:00
committed by mobile promotions
parent 96d3f396d0
commit dce49c9b2b

View File

@@ -313,14 +313,20 @@ void nvgpu_semaphore_pool_unmap(struct nvgpu_semaphore_pool *p,
"Unmapped semaphore pool! (idx=%llu)", p->page_idx); "Unmapped semaphore pool! (idx=%llu)", p->page_idx);
} }
static struct nvgpu_semaphore_pool *
nvgpu_semaphore_pool_from_ref(struct nvgpu_ref *ref)
{
return (struct nvgpu_semaphore_pool *)
((uintptr_t)ref - offsetof(struct nvgpu_semaphore_pool, ref));
}
/* /*
* Completely free a semaphore_pool. You should make sure this pool is not * Completely free a semaphore_pool. You should make sure this pool is not
* mapped otherwise there's going to be a memory leak. * mapped otherwise there's going to be a memory leak.
*/ */
static void nvgpu_semaphore_pool_free(struct nvgpu_ref *ref) static void nvgpu_semaphore_pool_free(struct nvgpu_ref *ref)
{ {
struct nvgpu_semaphore_pool *p = struct nvgpu_semaphore_pool *p = nvgpu_semaphore_pool_from_ref(ref);
container_of(ref, struct nvgpu_semaphore_pool, ref);
struct nvgpu_semaphore_sea *s = p->sema_sea; struct nvgpu_semaphore_sea *s = p->sema_sea;
/* Freeing a mapped pool is a bad idea. */ /* Freeing a mapped pool is a bad idea. */
@@ -469,10 +475,15 @@ struct nvgpu_semaphore *nvgpu_semaphore_alloc(struct channel_gk20a *ch)
return s; return s;
} }
static struct nvgpu_semaphore *nvgpu_semaphore_from_ref(struct nvgpu_ref *ref)
{
return (struct nvgpu_semaphore *)
((uintptr_t)ref - offsetof(struct nvgpu_semaphore, ref));
}
static void nvgpu_semaphore_free(struct nvgpu_ref *ref) static void nvgpu_semaphore_free(struct nvgpu_ref *ref)
{ {
struct nvgpu_semaphore *s = struct nvgpu_semaphore *s = nvgpu_semaphore_from_ref(ref);
container_of(ref, struct nvgpu_semaphore, ref);
nvgpu_semaphore_pool_put(s->location.pool); nvgpu_semaphore_pool_put(s->location.pool);