From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tomasz Figa Subject: Re: [PATCH v2 2/5] media: venus: add a routine to set venus state Date: Mon, 4 Jun 2018 21:54:25 +0900 Message-ID: References: <1527884768-22392-1-git-send-email-vgarodia@codeaurora.org> <1527884768-22392-3-git-send-email-vgarodia@codeaurora.org> <20180601212117.GD11565@jcrouse-lnx.qualcomm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: In-Reply-To: <20180601212117.GD11565@jcrouse-lnx.qualcomm.com> Sender: linux-kernel-owner@vger.kernel.org To: vgarodia@codeaurora.org, Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Mark Rutland , andy.gross@linaro.org, bjorn.andersson@linaro.org, Stanimir Varbanov , Linux Media Mailing List , Linux Kernel Mailing List , linux-arm-msm , linux-soc@vger.kernel.org, devicetree@vger.kernel.org, Alexandre Courbot List-Id: linux-arm-msm@vger.kernel.org Hi Jordan, Vikash, On Sat, Jun 2, 2018 at 6:21 AM Jordan Crouse wrote: > > On Sat, Jun 02, 2018 at 01:56:05AM +0530, Vikash Garodia wrote: [snip] > > +int venus_set_hw_state(enum tzbsp_video_state state, struct venus_core *core) > > +{ > > + int ret; > > + struct device *dev = core->dev; > > If you get rid of the log message as you should, you don't need this. > > > + void __iomem *reg_base = core->base; > > + > > + switch (state) { > > + case TZBSP_VIDEO_SUSPEND: > > + if (qcom_scm_is_available()) > > + ret = qcom_scm_set_remote_state(TZBSP_VIDEO_SUSPEND, 0); > > + else > > + writel_relaxed(1, reg_base + WRAPPER_A9SS_SW_RESET); > > You can just use core->base here and not bother making a local variable for it. > > > + break; > > + case TZBSP_VIDEO_RESUME: > > + if (qcom_scm_is_available()) > > + ret = qcom_scm_set_remote_state(TZBSP_VIDEO_RESUME, 0); > > + else > > + venus_reset_hw(core); > > + break; > > + default: > > + dev_err(dev, "invalid state\n"); > > state is a enum - you are highly unlikely to be calling it in your own code with > a random value. It is smart to have the default, but you don't need the log > message - that is just wasted space in the binary. > > > + break; > > + } > > There are three paths in the switch statement that could end up with 'ret' being > uninitialized here. Set it to 0 when you declare it. Does this actually compile? The compiler should detect that ret is used uninitialized. Setting it to 0 at declaration time actually prevents compiler from doing that and makes it impossible to catch cases when the ret should actually be non-zero, e.g. the invalid enum value case. Given that this function is supposed to substitute existing calls into qcom_scm_set_remote_state(), why not just do something like this: if (qcom_scm_is_available()) return qcom_scm_set_remote_state(state, 0); switch (state) { case TZBSP_VIDEO_SUSPEND: writel_relaxed(1, reg_base + WRAPPER_A9SS_SW_RESET); break; case TZBSP_VIDEO_RESUME: venus_reset_hw(core); break; } return 0; Best regards, Tomasz