[linux-sunxi] [PATCH 1/1] drm/sun4i: hdmi: Remove duplicate cleanup calls

2019-12-17 Thread Stefan Mavrodiev
When the HDMI unbinds drm_connector_cleanup() and drm_encoder_cleanup()
are called. This also happens when the connector and the encoder are
destroyed. This double call triggers a NULL pointer exception.

The patch fixes this by removing the cleanup calls in the unbind
function.

Signed-off-by: Stefan Mavrodiev 
---
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c 
b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
index a7c4654445c7..68d4644ac2dc 100644
--- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
@@ -685,8 +685,6 @@ static void sun4i_hdmi_unbind(struct device *dev, struct 
device *master,
struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
cec_unregister_adapter(hdmi->cec_adap);
-   drm_connector_cleanup(>connector);
-   drm_encoder_cleanup(>encoder);
i2c_del_adapter(hdmi->i2c);
i2c_put_adapter(hdmi->ddc_i2c);
clk_disable_unprepare(hdmi->mod_clk);
-- 
2.17.1

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/linux-sunxi/20191217124632.20820-1-stefan%40olimex.com.


[linux-sunxi] Re: [PATCH v12 1/7] dt-bindings: sun6i-dsi: Document A64 MIPI-DSI controller

2019-12-17 Thread Jagan Teki
On Tue, Dec 17, 2019 at 12:04 AM Maxime Ripard  wrote:
>
> On Mon, Dec 16, 2019 at 10:29:08PM +0530, Jagan Teki wrote:
> > On Mon, Dec 16, 2019 at 4:50 PM Maxime Ripard  wrote:
> > >
> > > On Mon, Dec 16, 2019 at 04:37:20PM +0530, Jagan Teki wrote:
> > > > On Wed, Dec 4, 2019 at 7:06 PM Maxime Ripard  wrote:
> > > > >
> > > > > On Tue, Dec 03, 2019 at 07:18:10PM +0530, Jagan Teki wrote:
> > > > > > The MIPI DSI controller in Allwinner A64 is similar to A33.
> > > > > >
> > > > > > But unlike A33, A64 doesn't have DSI_SCLK gating so it is valid
> > > > > > to have separate compatible for A64 on the same driver.
> > > > > >
> > > > > > DSI_SCLK uses mod clock-names on dt-bindings, so the same
> > > > > > is not required for A64.
> > > > > >
> > > > > > On that note
> > > > > > - A64 require minimum of 1 clock like the bus clock
> > > > > > - A33 require minimum of 2 clocks like both bus, mod clocks
> > > > > >
> > > > > > So, update dt-bindings so-that it can document both A33,
> > > > > > A64 bindings requirements.
> > > > > >
> > > > > > Reviewed-by: Rob Herring 
> > > > > > Signed-off-by: Jagan Teki 
> > > > > > ---
> > > > > > Changes for v12:
> > > > > > - Use 'enum' instead of oneOf+const
> > > > > >
> > > > > >  .../display/allwinner,sun6i-a31-mipi-dsi.yaml | 20 
> > > > > > +--
> > > > > >  1 file changed, 18 insertions(+), 2 deletions(-)
> > > > > >
> > > > > > diff --git 
> > > > > > a/Documentation/devicetree/bindings/display/allwinner,sun6i-a31-mipi-dsi.yaml
> > > > > >  
> > > > > > b/Documentation/devicetree/bindings/display/allwinner,sun6i-a31-mipi-dsi.yaml
> > > > > > index dafc0980c4fa..b91446475f35 100644
> > > > > > --- 
> > > > > > a/Documentation/devicetree/bindings/display/allwinner,sun6i-a31-mipi-dsi.yaml
> > > > > > +++ 
> > > > > > b/Documentation/devicetree/bindings/display/allwinner,sun6i-a31-mipi-dsi.yaml
> > > > > > @@ -15,7 +15,9 @@ properties:
> > > > > >"#size-cells": true
> > > > > >
> > > > > >compatible:
> > > > > > -const: allwinner,sun6i-a31-mipi-dsi
> > > > > > +enum:
> > > > > > +  - allwinner,sun6i-a31-mipi-dsi
> > > > > > +  - allwinner,sun50i-a64-mipi-dsi
> > > > > >
> > > > > >reg:
> > > > > >  maxItems: 1
> > > > > > @@ -24,6 +26,8 @@ properties:
> > > > > >  maxItems: 1
> > > > > >
> > > > > >clocks:
> > > > > > +minItems: 1
> > > > > > +maxItems: 2
> > > > > >  items:
> > > > > >- description: Bus Clock
> > > > > >- description: Module Clock
> > > > > > @@ -63,13 +67,25 @@ required:
> > > > > >- reg
> > > > > >- interrupts
> > > > > >- clocks
> > > > > > -  - clock-names
> > > > > >- phys
> > > > > >- phy-names
> > > > > >- resets
> > > > > >- vcc-dsi-supply
> > > > > >- port
> > > > > >
> > > > > > +allOf:
> > > > > > +  - if:
> > > > > > +  properties:
> > > > > > + compatible:
> > > > > > +   contains:
> > > > > > + const: allwinner,sun6i-a31-mipi-dsi
> > > > > > +  then:
> > > > > > +properties:
> > > > > > +  clocks:
> > > > > > +minItems: 2
> > > > > > +required:
> > > > > > +  - clock-names
> > > > > > +
> > > > >
> > > > > Your else condition should check that the number of clocks items is 1
> > > > > on the A64
> > > >
> > > > But the minItems mentioned as 1 in clocks, which is unchanged number
> > > > by default. doesn't it sufficient?
> > >
> > > In the main schema, it's said that the clocks property can have one or
> > > two elements (to cover the A31 case that has one, and the A64 case
> > > that has 2).
> > >
> > > This is fine.
> > >
> > > Later on, you enforce that the A64 has two elements, and this is fine
> > > too.
> >
> > Actually A31 case has 2 and A64 case has 1.
> >
> > >
> > > However, you never check that on the A31 you only have one clock, and
> > > you could very well have two and no one would notice.
> >
> > I did check A31 case for 2 but not in A64. this is what you mean? so
> > adding A64 check like below would fine?
> >
> > allOf:
> >   - if:
> >   properties:
> >  compatible:
> >contains:
> >  const: allwinner,sun6i-a31-mipi-dsi
>
> You need a new line here

I couldn't see new line before then: in example schema -
https://elixir.bootlin.com/linux/v5.5-rc2/source/Documentation/devicetree/bindings/example-schema.yaml#L208
May be a new changes for this ML or so?

>
> >   then:
>
> This is the wrong level of indentation, it needs to be at the same level than 
> if

True, I have seen it in example schema.

>
> > properties:
> >   clocks:
> > minItems: 2
>
> Newline
>
> > required:
> >   - clock-names
>
> Newline
>
> >   - if:
> >   properties:
> >  compatible:
> >contains:
> >  const: allwinner,sun50i-a64-mipi-dsi
> >   then:
> > properties:
> >   clocks:
> > minItems: 1
>
> (and same thing 

[linux-sunxi] Re: [PATCH 1/1] drm/sun4i: hdmi: Check for null pointer before cleanup

2019-12-17 Thread Stefan Mavrodiev

Hi,

On 12/17/19 1:49 PM, Maxime Ripard wrote:

On Tue, Dec 17, 2019 at 12:46:03PM +0100, Maxime Ripard wrote:

On Tue, Dec 17, 2019 at 08:45:07AM +0200, Stefan Mavrodiev wrote:

Hi,

On 12/16/19 6:12 PM, Maxime Ripard wrote:

Hi,

On Mon, Dec 16, 2019 at 04:43:48PM +0200, Stefan Mavrodiev wrote:

It's possible hdmi->connector and hdmi->encoder divices to be NULL.
This can happen when building as kernel module and you try to remove
the module.

This patch make simple null check, before calling the cleanup functions.

Signed-off-by: Stefan Mavrodiev 
---
   drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 --
   1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c 
b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
index a7c4654445c7..b61e00f2ecb8 100644
--- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct 
device *master,
struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);

cec_unregister_adapter(hdmi->cec_adap);
-   drm_connector_cleanup(>connector);
-   drm_encoder_cleanup(>encoder);
+   if (hdmi->connector.dev)
+   drm_connector_cleanup(>connector);
+   if (hdmi->encoder.dev)
+   drm_encoder_cleanup(>encoder);

Hmmm, this doesn't look right. Do you have more information on how you
can reproduce it?

Just build sun4i_drm_hdmi as module (CONFIG_DRM_SUN4I_HDMI=m). Then try to
unload the module:

# rmmod sun4i_drm_hdmi

And you get this:

Unable to handle kernel NULL pointer dereference at virtual address 
pgd = 6b032436
[] *pgd=
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in: sun4i_drm_hdmi(-)
CPU: 0 PID: 1081 Comm: rmmod Not tainted 5.5.0-rc1-00030-g6ec417030d93 #33
Hardware name: Allwinner sun7i (A20) Family
PC is at drm_connector_cleanup+0x40/0x208
LR is at sun4i_hdmi_unbind+0x10/0x54 [sun4i_drm_hdmi]
...


I've tested that with sunxi/for-next branch on A20-OLinuXino board.

Yeah, you detailed the symptoms nicely in the commit log, but my point
was that we shouldn't end up in that situation in the first place.

Your patch works around it, but it doesn't fix the underlying
issue. Is drm_connector_cleanup (or the encoder variant) called twice?

Answering myself, yes it is. It's both the destroy call back and
called in unbind. We should just remove the one in the unbind then.


Should I do this or leave it to you?

Stefan



Maxime


--
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/linux-sunxi/83088170-1753-6a2f-aa25-c4f6f54462d6%40olimex.com.