lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 4 Feb 2015 10:15:44 +0000
From:	James Hogan <james.hogan@...tec.com>
To:	Sifan Naeem <sifan.naeem@...tec.com>, <mchehab@....samsung.com>
CC:	<linux-kernel@...r.kernel.org>, <linux-media@...r.kernel.org>
Subject: Re: [PATCH] rc: img-ir: Add and enable sys clock for IR

Hi Sifan,

On 03/02/15 17:30, Sifan Naeem wrote:
> Gets a handle to the system clock, already described in the binding
> document, and calls the appropriate common clock
> framework functions to mark it prepared/enabled, the common clock
> framework initially enables the clock and doesn't disable it at least
> until the device/driver is removed.
> The system clock to IR is needed for the driver to communicate with the
> IR hardware via MMIO accesses on the system bus, so it must not be
> disabled during use or the driver will malfunction.
> 
> Signed-off-by: Sifan Naeem <sifan.naeem@...tec.com>
> ---
>  drivers/media/rc/img-ir/img-ir-core.c |   13 +++++++++----
>  drivers/media/rc/img-ir/img-ir.h      |    2 ++
>  2 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/rc/img-ir/img-ir-core.c b/drivers/media/rc/img-ir/img-ir-core.c
> index 77c78de..783dd21 100644
> --- a/drivers/media/rc/img-ir/img-ir-core.c
> +++ b/drivers/media/rc/img-ir/img-ir-core.c
> @@ -60,6 +60,8 @@ static void img_ir_setup(struct img_ir_priv *priv)
>  
>  	if (!IS_ERR(priv->clk))
>  		clk_prepare_enable(priv->clk);
> +	if (!IS_ERR(priv->sys_clk))
> +		clk_prepare_enable(priv->sys_clk);

The patch mostly looks good, however I just realised this only enables
the system clock after it has already used the register interface. To be
safe it should really be enabled before any hardware accesses, so before
img_ir_ident() is called (and certainly before the img_ir_setup_raw()
and img_ir_setup_hw() functions are called since they set up the default
timings / irq mask etc).

Currently img_ir_probe_raw() and img_ir_probe_hw() don't appear to
access the hardware, but I can imagine they may want to access hardware
in future to read the revision register, so I think its worth doing it
from img_ir_probe() before they get called too, which should also ensure
the ISR doesn't get called with sysclock disabled (obviously error
handling in probe function would need to take it into account).

I suspect you would see this causing a problem when the driver is built
as a module and loaded after unused clocks have been automatically
disabled by the common clock framework at the end of the init sequence.

Thanks
James

>  }
>  
>  static void img_ir_ident(struct img_ir_priv *priv)
> @@ -110,10 +112,11 @@ static int img_ir_probe(struct platform_device *pdev)
>  	priv->clk = devm_clk_get(&pdev->dev, "core");
>  	if (IS_ERR(priv->clk))
>  		dev_warn(&pdev->dev, "cannot get core clock resource\n");
> -	/*
> -	 * The driver doesn't need to know about the system ("sys") or power
> -	 * modulation ("mod") clocks yet
> -	 */
> +
> +	/* Get sys clock */
> +	priv->sys_clk = devm_clk_get(&pdev->dev, "sys");
> +	if (IS_ERR(priv->sys_clk))
> +		dev_warn(&pdev->dev, "cannot get sys clock resource\n");
>  
>  	/* Set up raw & hw decoder */
>  	error = img_ir_probe_raw(priv);
> @@ -152,6 +155,8 @@ static int img_ir_remove(struct platform_device *pdev)
>  
>  	if (!IS_ERR(priv->clk))
>  		clk_disable_unprepare(priv->clk);
> +	if (!IS_ERR(priv->sys_clk))
> +		clk_disable_unprepare(priv->sys_clk);
>  	return 0;
>  }
>  
> diff --git a/drivers/media/rc/img-ir/img-ir.h b/drivers/media/rc/img-ir/img-ir.h
> index 2ddf560..f1387c0 100644
> --- a/drivers/media/rc/img-ir/img-ir.h
> +++ b/drivers/media/rc/img-ir/img-ir.h
> @@ -138,6 +138,7 @@ struct clk;
>   * @dev:		Platform device.
>   * @irq:		IRQ number.
>   * @clk:		Input clock.
> + * @sys_clk:		System clock.
>   * @reg_base:		Iomem base address of IR register block.
>   * @lock:		Protects IR registers and variables in this struct.
>   * @raw:		Driver data for raw decoder.
> @@ -147,6 +148,7 @@ struct img_ir_priv {
>  	struct device		*dev;
>  	int			irq;
>  	struct clk		*clk;
> +	struct clk		*sys_clk;
>  	void __iomem		*reg_base;
>  	spinlock_t		lock;
>  
> 


Download attachment "signature.asc" of type "application/pgp-signature" (820 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ