From 0837b6988cab2d6f2920033f6584da2e7324e59f Mon Sep 17 00:00:00 2001 From: Scott Long Date: Sat, 12 Jan 2019 12:21:41 -0800 Subject: [PATCH] gpu: nvgpu: container_of() changes to clk arb 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 references to container_of() references in clk arb code: * nvgpu_clk_dev_from_refcount * nvgpu_clk_session_from_refcount 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: I612990e9c27f10d0ce3ac76729529aa1eb15d42a Signed-off-by: Scott Long Reviewed-on: https://git-master.nvidia.com/r/1993796 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Adeel Raza Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/pmu/clk/clk_arb.c | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/nvgpu/common/pmu/clk/clk_arb.c b/drivers/gpu/nvgpu/common/pmu/clk/clk_arb.c index b0f9cbd9e..3c39d0792 100644 --- a/drivers/gpu/nvgpu/common/pmu/clk/clk_arb.c +++ b/drivers/gpu/nvgpu/common/pmu/clk/clk_arb.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -669,10 +669,16 @@ int nvgpu_clk_arb_init_session(struct gk20a *g, return 0; } +static struct nvgpu_clk_dev * +nvgpu_clk_dev_from_refcount(struct nvgpu_ref *refcount) +{ + return (struct nvgpu_clk_dev *) + ((uintptr_t)refcount - offsetof(struct nvgpu_clk_dev, refcount)); +}; + void nvgpu_clk_arb_free_fd(struct nvgpu_ref *refcount) { - struct nvgpu_clk_dev *dev = container_of(refcount, - struct nvgpu_clk_dev, refcount); + struct nvgpu_clk_dev *dev = nvgpu_clk_dev_from_refcount(refcount); struct nvgpu_clk_session *session = dev->session; struct gk20a *g = session->g; @@ -682,10 +688,17 @@ void nvgpu_clk_arb_free_fd(struct nvgpu_ref *refcount) nvgpu_kfree(g, dev); } +static struct nvgpu_clk_session * +nvgpu_clk_session_from_refcount(struct nvgpu_ref *refcount) +{ + return (struct nvgpu_clk_session *) + ((uintptr_t)refcount - offsetof(struct nvgpu_clk_session, refcount)); +}; + void nvgpu_clk_arb_free_session(struct nvgpu_ref *refcount) { - struct nvgpu_clk_session *session = container_of(refcount, - struct nvgpu_clk_session, refcount); + struct nvgpu_clk_session *session = + nvgpu_clk_session_from_refcount(refcount); struct nvgpu_clk_arb *arb = session->g->clk_arb; struct gk20a *g = session->g; struct nvgpu_clk_dev *dev, *tmp;