Re: [PATCH v3 07/13] tty: Convert ->dtr_rts() to take bool argument

2023-01-11 Thread Johan Hovold
On Wed, Jan 11, 2023 at 04:23:25PM +0200, Ilpo Järvinen wrote:
> Convert the raise/on parameter in ->dtr_rts() to bool through the
> callchain. The parameter is used like bool. In USB serial, there
> remains a few implicit bool -> larger type conversions because some
> devices use u8 in their control messages.
> 
> In moxa_tiocmget(), dtr variable was reused for line status which
> requires int so use a separate variable for status.
> 
> Reviewed-by: Jiri Slaby 
> Signed-off-by: Ilpo Järvinen 
> ---
>  drivers/char/pcmcia/synclink_cs.c|  4 +--
>  drivers/mmc/core/sdio_uart.c |  4 +--
>  drivers/staging/greybus/uart.c   |  2 +-
>  drivers/tty/amiserial.c  |  2 +-
>  drivers/tty/hvc/hvc_console.c|  4 +--
>  drivers/tty/hvc/hvc_console.h|  2 +-
>  drivers/tty/hvc/hvc_iucv.c   |  4 +--
>  drivers/tty/moxa.c   | 54 ++--
>  drivers/tty/mxser.c  |  2 +-
>  drivers/tty/n_gsm.c  |  2 +-
>  drivers/tty/serial/serial_core.c |  8 ++---
>  drivers/tty/synclink_gt.c|  2 +-
>  drivers/tty/tty_port.c   |  4 +--
>  drivers/usb/class/cdc-acm.c  |  2 +-
>  drivers/usb/serial/ch341.c   |  2 +-
>  drivers/usb/serial/cp210x.c  |  4 +--
>  drivers/usb/serial/cypress_m8.c  |  6 ++--
>  drivers/usb/serial/digi_acceleport.c |  6 ++--
>  drivers/usb/serial/f81232.c  |  2 +-
>  drivers/usb/serial/f81534.c  |  2 +-
>  drivers/usb/serial/ftdi_sio.c|  2 +-
>  drivers/usb/serial/ipw.c |  2 +-
>  drivers/usb/serial/keyspan.c |  2 +-
>  drivers/usb/serial/keyspan_pda.c |  2 +-
>  drivers/usb/serial/mct_u232.c|  4 +--
>  drivers/usb/serial/mxuport.c |  2 +-
>  drivers/usb/serial/pl2303.c  |  2 +-
>  drivers/usb/serial/quatech2.c|  2 +-
>  drivers/usb/serial/sierra.c  |  2 +-
>  drivers/usb/serial/spcp8x5.c |  2 +-
>  drivers/usb/serial/ssu100.c  |  2 +-
>  drivers/usb/serial/upd78f0730.c  |  6 ++--
>  drivers/usb/serial/usb-serial.c  |  2 +-
>  drivers/usb/serial/usb-wwan.h|  2 +-
>  drivers/usb/serial/usb_wwan.c|  2 +-
>  drivers/usb/serial/xr_serial.c   |  6 ++--
>  include/linux/tty_port.h |  4 +--
>  include/linux/usb/serial.h   |  2 +-
>  38 files changed, 84 insertions(+), 82 deletions(-)

Same here. No need to lump the tty-port changes with USB-serial changes.

Johan


Re: [PATCH v3 11/13] tty/serial: Call ->dtr_rts() parameter active consistently

2023-01-11 Thread Johan Hovold
On Wed, Jan 11, 2023 at 04:23:29PM +0200, Ilpo Järvinen wrote:
> Convert various parameter names for ->dtr_rts() and related functions
> from onoff, on, and raise to active.
> 
> Reviewed-by: Jiri Slaby 
> Signed-off-by: Ilpo Järvinen 
> ---
>  drivers/char/pcmcia/synclink_cs.c | 6 +++---
>  drivers/mmc/core/sdio_uart.c  | 6 +++---
>  drivers/staging/greybus/uart.c| 4 ++--
>  drivers/tty/amiserial.c   | 4 ++--
>  drivers/tty/hvc/hvc_console.h | 2 +-
>  drivers/tty/hvc/hvc_iucv.c| 6 +++---
>  drivers/tty/mxser.c   | 4 ++--
>  drivers/tty/n_gsm.c   | 4 ++--
>  drivers/tty/serial/serial_core.c  | 8 
>  drivers/tty/synclink_gt.c | 4 ++--
>  include/linux/tty_port.h  | 4 ++--
>  include/linux/usb/serial.h| 2 +-
>  12 files changed, 27 insertions(+), 27 deletions(-)

> diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h
> index c44e489de0ff..edf685a24f7c 100644
> --- a/include/linux/tty_port.h
> +++ b/include/linux/tty_port.h
> @@ -16,7 +16,7 @@ struct tty_struct;
>  /**
>   * struct tty_port_operations -- operations on tty_port
>   * @carrier_raised: return true if the carrier is raised on @port
> - * @dtr_rts: raise the DTR line if @raise is true, otherwise lower DTR
> + * @dtr_rts: raise the DTR line if @active is true, otherwise lower DTR
>   * @shutdown: called when the last close completes or a hangup finishes IFF 
> the
>   *   port was initialized. Do not use to free resources. Turn off the device
>   *   only. Called under the port mutex to serialize against @activate and
> @@ -32,7 +32,7 @@ struct tty_struct;
>   */
>  struct tty_port_operations {
>   bool (*carrier_raised)(struct tty_port *port);
> - void (*dtr_rts)(struct tty_port *port, bool raise);
> + void (*dtr_rts)(struct tty_port *port, bool active);
>   void (*shutdown)(struct tty_port *port);
>   int (*activate)(struct tty_port *port, struct tty_struct *tty);
>   void (*destruct)(struct tty_port *port);
> diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
> index bad343c5e8a7..33afd9f3ebbe 100644
> --- a/include/linux/usb/serial.h
> +++ b/include/linux/usb/serial.h
> @@ -292,7 +292,7 @@ struct usb_serial_driver {
>   struct serial_icounter_struct *icount);
>   /* Called by the tty layer for port level work. There may or may not
>  be an attached tty at this point */
> - void (*dtr_rts)(struct usb_serial_port *port, bool on);
> + void (*dtr_rts)(struct usb_serial_port *port, bool active);

This is not a tty_port callback so this change does not belong in this
patch.

>   bool (*carrier_raised)(struct usb_serial_port *port);
>   /* Called by the usb serial hooks to allow the user to rework the
>  termios state */

Johan


Re: [PATCH v2 1/2] serial: 8250: SERIAL_8250_FSL should not default to y when compile-testing

2021-09-24 Thread Johan Hovold
On Fri, Sep 24, 2021 at 09:12:30AM +0200, Geert Uytterhoeven wrote:
> Commit b1442c55ce8977aa ("serial: 8250: extend compile-test coverage")
> added compile-test support to the Freescale 16550 driver.  However, as
> SERIAL_8250_FSL is an invisible symbol, merely enabling compile-testing
> now enables this driver.
> 
> Fix this by dropping the COMPILE_TEST default again, but making the
> SERIAL_8250_FSL symbol visible instead.
> 
> Fixes: b1442c55ce8977aa ("serial: 8250: extend compile-test coverage")
> Signed-off-by: Geert Uytterhoeven 
> ---
> v2:
>   - Split in two parts.

I realised that we can do better than this. I've prepared a patch that
preserves the old behaviour of always enabling the option on platforms
that may need it while also not enabling it by default when compile
testing.

Note that SERIAL_8250_FSL only enables a workaround for an erratum in
the Freescale UARTs in the 8250 driver (leaving the later added ACPI
support aside) and we shouldn't make it easier to disable it by mistake.

> ---
>  drivers/tty/serial/8250/Kconfig | 7 +--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
> index 808268edd2e82a45..0af96f3adab517f6 100644
> --- a/drivers/tty/serial/8250/Kconfig
> +++ b/drivers/tty/serial/8250/Kconfig
> @@ -361,9 +361,12 @@ config SERIAL_8250_BCM2835AUX
> If unsure, say N.
>  
>  config SERIAL_8250_FSL
> - bool
> + bool "Freescale 16550-style UART support (8250 based driver)"
>   depends on SERIAL_8250_CONSOLE
> - default PPC || ARM || ARM64 || COMPILE_TEST
> + default PPC || ARM || ARM64
> + help
> +   Selecting this option will add support for the 16550-style serial
> +   port hardware found on Freescale SoCs.
>  
>  config SERIAL_8250_DW
>   tristate "Support for Synopsys DesignWare 8250 quirks"

Johan


Re: [PATCH] serial: 8250: SERIAL_8250_FSL should not default to y when compile-testing

2021-09-16 Thread Johan Hovold
On Thu, Sep 16, 2021 at 10:55:49AM +0200, Geert Uytterhoeven wrote:
> Hi Johan,
> 
> On Thu, Sep 16, 2021 at 10:46 AM Johan Hovold  wrote:
> > On Wed, Sep 15, 2021 at 02:56:52PM +0200, Geert Uytterhoeven wrote:
> > > Commit b1442c55ce8977aa ("serial: 8250: extend compile-test coverage")
> > > added compile-test support to the Freescale 16550 driver.  However, as
> > > SERIAL_8250_FSL is an invisible symbol, merely enabling COMPILE_TEST now
> > > enables this driver.
> > >
> > > Fix this by making SERIAL_8250_FSL visible.  Tighten the dependencies to
> > > prevent asking the user about this driver when configuring a kernel
> > > without appropriate Freescale SoC or ACPI support.
> >
> > This tightening is arguable a separate change which risk introducing
> > regressions if you get it wrong and should go in a separate patch at
> > least.
> 
> Getting it wrong would indeed be a regression, but not tightening
> that at the same time would mean I have to send a separate patch with
> a Fixes tag referring to this fix, following this template:
> 
> foo should depend on bar
> 
> The foo hardware is only present on bar SoCs.  Hence add a
> dependency on bar, to prevent asking the user about this driver
> when configuring a kernel without bar support.

I know this is a pet peeve of yours, but asking users about one more
symbol when configuring their kernels is hardly something that requires
a Fixes tag.

Either way it's a pretty weak argument for not separating the change.

Johan


Re: [PATCH] serial: 8250: SERIAL_8250_FSL should not default to y when compile-testing

2021-09-16 Thread Johan Hovold
On Wed, Sep 15, 2021 at 02:56:52PM +0200, Geert Uytterhoeven wrote:
> Commit b1442c55ce8977aa ("serial: 8250: extend compile-test coverage")
> added compile-test support to the Freescale 16550 driver.  However, as
> SERIAL_8250_FSL is an invisible symbol, merely enabling COMPILE_TEST now
> enables this driver.
> 
> Fix this by making SERIAL_8250_FSL visible.  Tighten the dependencies to
> prevent asking the user about this driver when configuring a kernel
> without appropriate Freescale SoC or ACPI support.

This tightening is arguable a separate change which risk introducing
regressions if you get it wrong and should go in a separate patch at
least.

> Fixes: b1442c55ce8977aa ("serial: 8250: extend compile-test coverage")
> Signed-off-by: Geert Uytterhoeven 
> ---
> Yes, it's ugly, but I see no better solution. Do you?
> 
>  drivers/tty/serial/8250/Kconfig | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
> index 808268edd2e82a45..a2978b31144e94f2 100644
> --- a/drivers/tty/serial/8250/Kconfig
> +++ b/drivers/tty/serial/8250/Kconfig
> @@ -361,9 +361,13 @@ config SERIAL_8250_BCM2835AUX
> If unsure, say N.
>  
>  config SERIAL_8250_FSL
> - bool
> + bool "Freescale 16550-style UART support (8250 based driver)"
>   depends on SERIAL_8250_CONSOLE
> - default PPC || ARM || ARM64 || COMPILE_TEST
> + depends on FSL_SOC || ARCH_LAYERSCAPE || SOC_LS1021A || (ARM64 && ACPI) 
> || COMPILE_TEST
> + default FSL_SOC || ARCH_LAYERSCAPE || SOC_LS1021A || (ARM64 && ACPI)

I'd suggest just doing

bool "Freescale 16550-style UART support (8250 based driver)"
depends on SERIAL_8250_CONSOLE
default PPC || ARM || ARM64

Since neither of the symbols you add to that "depends on" line is an
actual build or runtime dependency.

Then you can refine the "default" line in a follow up (or argue why you
think there should be a "depends on FSL_SOC || ...").

> + help
> +   Selecting this option will add support for the 16550-style serial
> +   port hardware found on Freescale SoCs.
>  
>  config SERIAL_8250_DW
>   tristate "Support for Synopsys DesignWare 8250 quirks"

Johan


Re: [PATCH] bus: Make remove callback return void

2021-07-06 Thread Johan Hovold
On Tue, Jul 06, 2021 at 11:50:37AM +0200, Uwe Kleine-König wrote:
> The driver core ignores the return value of this callback because there
> is only little it can do when a device disappears.
> 
> This is the final bit of a long lasting cleanup quest where several
> buses were converted to also return void from their remove callback.
> Additionally some resource leaks were fixed that were caused by drivers
> returning an error code in the expectation that the driver won't go
> away.
> 
> With struct bus_type::remove returning void it's prevented that newly
> implemented buses return an ignored error code and so don't anticipate
> wrong expectations for driver authors.
> 
> Signed-off-by: Uwe Kleine-König 

>  drivers/staging/greybus/gbphy.c   | 4 +---

>  drivers/usb/serial/bus.c  | 4 +---

>  include/linux/device/bus.h| 2 +-

Acked-by: Johan Hovold 


Re: [PATCH 6/9] tty: hvc_console: Fix coding style issues of block comments

2021-05-21 Thread Johan Hovold
On Thu, May 20, 2021 at 08:21:39AM -0700, Joe Perches wrote:
> On Thu, 2021-05-20 at 10:21 +0200, Johan Hovold wrote:
> > On Tue, May 18, 2021 at 12:01:22PM +0800, Xiaofei Tan wrote:
> > > On 2021/5/17 22:15, Johan Hovold wrote:

> > > > How is this an improvement? First, the multi-line comment style is
> > > > 
> > > > /*
> > > >  * ...
> > > >  */
> > > > 
> > > 
> > > Yes, mostly we use this style. I can follow it if new version is needed.
> > 
> > This is the preferred style outside of networking.
> > 
> > > BTW, How about add the '/*' check into checkpatch.pl?
> > 
> > Checkpatch already has too many checks IMO
> 
> I sometimes agree.  What checkpatch messages do you think are excessive?

The "unsigned" -> "unsigned int" one comes to mind (at least when
running with -f).

Most of the questionable ones are probably hidden behind --subjective,
but due to the unfortunate alias of that switch as --strict, people
don't get the message to use their own judgement and instead think
they'll get a gold star for "full compliance".

So my issue isn't so much which checkpatch itself rather than with how
it is being used and promoted, for example, to introduce aspiring
developers to kernel development in staging.

It's a great tool to run on your own patches before submission (as was
originally intended judging by the apt name), but if I could change
something I'd drop the --strict alias for the --subjective checks and
disable that switch for staging.

Perhaps also add a warning or similar when running with -f on in-tree
code outside of staging.
 
> > and I'm a bit surprised that
> > it doesn't check this already. Perhaps it's because you used the -f to
> > run checkpatch on in-kernel code, which you should not.
> 
> Likely not.  If it was run on a suggested patch, checkpatch doesn't emit
> many messages on unmodified patch context lines.  And it shouldn't.

Right, but here it appears to have been run using -f on in-tree code.

You could still check for this when adding new comments, and perhaps it
already does.

> > it's just that you
> > introduce noise in the logs and do pointless changes of context which
> > makes it harder to use tools like git blame and makes backporting harder
> > for no good reason.
> 
> Pretty pointless metric IMO.  Context changes in comments are mostly harmless.

This isn't just about comment changes but the whole array of
white-space shifting and other pendantry. And also reformatted comments
makes it harder to do code forensics.

> IMO: backporting of these sorts non-bug fix changes is done _far_ too often.

I have yet to see AUTOSEL pick up white-space cleanups but there are
certainly a few non-bug-fix patches currently being backported.

Johan


Re: [PATCH 6/9] tty: hvc_console: Fix coding style issues of block comments

2021-05-20 Thread Johan Hovold
On Thu, May 20, 2021 at 09:21:25PM +0800, Xiaofei Tan wrote:

> > Checkpatch already has too many checks IMO and I'm a bit surprised that
> > it doesn't check this already. Perhaps it's because you used the -f to
> > run checkpatch on in-kernel code, which you should not.
> >
> >>> Second, that sentence is not capitalised so why do add a period?
> >>>
> >>
> >> How about capitalize the sentence, or just remove the period ?
> >
> > How about just leaving this unchanged?
> 
> OK
> And I will keep the patch 8/9, and combine space issues into
> one new patch, and remove the others.

Yeah, 8/9 is arguably a fix even if it's for a very minor issue
(repeated words in a comment).

It doesn't look like any of the white space issues are worth fixing,
though. Such pedantry can usually be addressed when the code in question
is being modified for other reasons.

Johan


Re: [PATCH 6/9] tty: hvc_console: Fix coding style issues of block comments

2021-05-20 Thread Johan Hovold
On Tue, May 18, 2021 at 12:01:22PM +0800, Xiaofei Tan wrote:
> Hi Johan,
> 
> Thanks for reviewing this patch.
> 
> On 2021/5/17 22:15, Johan Hovold wrote:
> > On Mon, May 17, 2021 at 02:37:10PM +0800, Xiaofei Tan wrote:
> >> Fix coding style issues of block comments, reported by checkpatch.pl.
> >> Besides, add a period at the end of the sentenses.
> >>
> >> Signed-off-by: Xiaofei Tan 
> >> ---
> >>  drivers/tty/hvc/hvc_console.c | 15 ++-
> >>  1 file changed, 10 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
> >> index 39018e5..a61cdf0 100644
> >> --- a/drivers/tty/hvc/hvc_console.c
> >> +++ b/drivers/tty/hvc/hvc_console.c
> >> @@ -177,7 +177,8 @@ static void hvc_console_print(struct console *co, 
> >> const char *b,
> >>r = cons_ops[index]->put_chars(vtermnos[index], c, i);
> >>if (r <= 0) {
> >>/* throw away characters on error
> >> -   * but spin in case of -EAGAIN */
> >> +   * but spin in case of -EAGAIN.
> >> +   */
> >
> > How is this an improvement? First, the multi-line comment style is
> >
> > /*
> >  * ...
> >  */
> >
> 
> Yes, mostly we use this style. I can follow it if new version is needed.

This is the preferred style outside of networking.

> BTW, How about add the '/*' check into checkpatch.pl?

Checkpatch already has too many checks IMO and I'm a bit surprised that
it doesn't check this already. Perhaps it's because you used the -f to
run checkpatch on in-kernel code, which you should not.

> > Second, that sentence is not capitalised so why do add a period?
> >
> 
> How about capitalize the sentence, or just remove the period ?

How about just leaving this unchanged?

> > Third, why are you sending checkpatch.pl cleanups for files outside of
> > staging?
> >
> 
> I'm sorry, Is this a rule, or kind of tradition? I've never heard of 
> this before.

Many subsystems reject pure style changes unless you're also doing some
real changes to the code in question. This is a good default rule, even
if some maintainers may occasionally accept churn like this.

You appear to be paid to do kernel work. Why don't you start fixing bugs
or help out reviewing new code instead of sending trivial patches like
this? We can always need another hand.

But if all you you want is to increase your company patch count then
please go work in drivers/staging where most trivial style changes are
currently accepted.

> > Unless doing some real changes to the files in question as well this is
> > mostly just churn and noise that makes it harder to backport fixes and
> > do code forensics for no real gain.
> 
> I'm not sure. But if cleanup patches have made it hard to backport fixes 
> and do code forensics, then the code quality may not be
> good enough.

No, that has nothing to do with code quality, it's just that you
introduce noise in the logs and do pointless changes of context which
makes it harder to use tools like git blame and makes backporting harder
for no good reason.

Johan


Re: [PATCH 6/9] tty: hvc_console: Fix coding style issues of block comments

2021-05-17 Thread Johan Hovold
On Mon, May 17, 2021 at 02:37:10PM +0800, Xiaofei Tan wrote:
> Fix coding style issues of block comments, reported by checkpatch.pl.
> Besides, add a period at the end of the sentenses.
> 
> Signed-off-by: Xiaofei Tan 
> ---
>  drivers/tty/hvc/hvc_console.c | 15 ++-
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
> index 39018e5..a61cdf0 100644
> --- a/drivers/tty/hvc/hvc_console.c
> +++ b/drivers/tty/hvc/hvc_console.c
> @@ -177,7 +177,8 @@ static void hvc_console_print(struct console *co, const 
> char *b,
>   r = cons_ops[index]->put_chars(vtermnos[index], c, i);
>   if (r <= 0) {
>   /* throw away characters on error
> -  * but spin in case of -EAGAIN */
> +  * but spin in case of -EAGAIN.
> +  */

How is this an improvement? First, the multi-line comment style is

/*
 * ...
 */

Second, that sentence is not capitalised so why do add a period?

Third, why are you sending checkpatch.pl cleanups for files outside of
staging?

Unless doing some real changes to the files in question as well this is
mostly just churn and noise that makes it harder to backport fixes and
do code forensics for no real gain.

Greg may disagree, but I don't think we should be encouraging this kind
of patches.

Johan


Re: [PATCH] tty: serial: cpm_uart: Fix behaviour for non existing GPIOs

2020-06-08 Thread Johan Hovold
On Sat, Jun 06, 2020 at 07:30:21AM +, Christophe Leroy wrote:
> devm_gpiod_get_index() doesn't return NULL but -ENOENT when the
> requested GPIO doesn't exist,  leading to the following messages:
> 
> [2.742468] gpiod_direction_input: invalid GPIO (errorpointer)
> [2.748147] can't set direction for gpio #2: -2
> [2.753081] gpiod_direction_input: invalid GPIO (errorpointer)
> [2.758724] can't set direction for gpio #3: -2
> [2.763666] gpiod_direction_output: invalid GPIO (errorpointer)
> [2.769394] can't set direction for gpio #4: -2
> [2.774341] gpiod_direction_input: invalid GPIO (errorpointer)
> [2.779981] can't set direction for gpio #5: -2
> [2.784545] ff000a20.serial: ttyCPM1 at MMIO 0xfff00a20 (irq = 39, 
> base_baud = 825) is a CPM UART
> 
> Use IS_ERR_OR_NULL() to properly check gpiod validity.

Why check for NULL at all?

> Fixes: 97cbaf2c829b ("tty: serial: cpm_uart: Convert to use GPIO descriptors")
> Cc: sta...@vger.kernel.org
> Cc: Linus Walleij 
> Signed-off-by: Christophe Leroy 
> ---
>  drivers/tty/serial/cpm_uart/cpm_uart_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c 
> b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> index a04f74d2e854..3cbe24802296 100644
> --- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> +++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> @@ -1217,7 +1217,7 @@ static int cpm_uart_init_port(struct device_node *np,
>  
>   gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
>  
> - if (gpiod) {
> + if (!IS_ERR_OR_NULL(gpiod)) {
>   if (i == GPIO_RTS || i == GPIO_DTR)
>   ret = gpiod_direction_output(gpiod, 0);
>   else

Johan


Re: [PATCH net 11/16] net: ethernet: marvell: mvneta: fix fixed-link phydev leaks

2020-05-08 Thread Johan Hovold
On Fri, May 08, 2020 at 03:35:02AM +0530, Naresh Kamboju wrote:
> On Thu, 7 May 2020 at 16:43, Greg Kroah-Hartman
>  wrote:
> >
> 
> > > >
> > > > Greg, 3f65047c853a ("of_mdio: add helper to deregister fixed-link
> > > > PHYs") needs to be backported as well for these.
> > > >
> > > > Original series can be found here:
> > > >
> > > > 
> > > > https://lkml.kernel.org/r/1480357509-28074-1-git-send-email-jo...@kernel.org
> > >
> > > Ah, thanks for that, I thought I dropped all of the ones that caused
> > > build errors, but missed the above one.  I'll go take the whole series
> > > instead.
> >
> > This should now all be fixed up, thanks.
> 
> While building kernel Image for arm architecture on stable-rc 4.4 branch
> the following build error found.
> 
> of_mdio: add helper to deregister fixed-link PHYs
> commit 3f65047c853a2a5abcd8ac1984af3452b5df4ada upstream.
> 
> Add helper to deregister fixed-link PHYs registered using
> of_phy_register_fixed_link().
> 
> Convert the two drivers that care to deregister their fixed-link PHYs to
> use the new helper, but note that most drivers currently fail to do so.
> 
> Signed-off-by: Johan Hovold 
> Signed-off-by: David S. Miller 
> [only take helper function for 4.4.y - gregkh]
> 
>  # make -sk KBUILD_BUILD_USER=TuxBuild -C/linux -j16 ARCH=arm
> CROSS_COMPILE=arm-linux-gnueabihf- HOSTCC=gcc CC="sccache
> arm-linux-gnueabihf-gcc" O=build zImage
> 70 #
> 71 ../drivers/of/of_mdio.c: In function ‘of_phy_deregister_fixed_link’:
> 72 ../drivers/of/of_mdio.c:379:2: error: implicit declaration of
> function ‘fixed_phy_unregister’; did you mean ‘fixed_phy_register’?
> [-Werror=implicit-function-declaration]
> 73  379 | fixed_phy_unregister(phydev);
> 74  | ^~~~
> 75  | fixed_phy_register
> 76 ../drivers/of/of_mdio.c:381:22: error: ‘struct phy_device’ has no
> member named ‘mdio’; did you mean ‘mdix’?
> 77  381 | put_device(>mdio.dev); /* of_phy_find_device() */
> 78  | ^~~~
> 79  | mdix

Another dependency: 5bcbe0f35fb1 ("phy: fixed: Fix removal of phys.")

Greg, these patches are from four years ago so can't really remember if
there are other dependencies or reasons against backporting them (the
missing stable tags are per Dave's preference), sorry.

The cover letter also mentions another dependency, but that may just
have been some context conflict.

Perhaps you better drop these unless you want to review them closer.

Johan


Re: [PATCH net 11/16] net: ethernet: marvell: mvneta: fix fixed-link phydev leaks

2020-05-07 Thread Johan Hovold
On Thu, May 07, 2020 at 12:27:53AM +0530, Naresh Kamboju wrote:
> On Tue, 29 Nov 2016 at 00:00, Johan Hovold  wrote:
> >
> > Make sure to deregister and free any fixed-link PHY registered using
> > of_phy_register_fixed_link() on probe errors and on driver unbind.
> >
> > Fixes: 83895bedeee6 ("net: mvneta: add support for fixed links")
> > Signed-off-by: Johan Hovold 
> > ---
> >  drivers/net/ethernet/marvell/mvneta.c | 5 +
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/marvell/mvneta.c 
> > b/drivers/net/ethernet/marvell/mvneta.c
> > index 0c0a45af950f..707bc4680b9b 100644
> > --- a/drivers/net/ethernet/marvell/mvneta.c
> > +++ b/drivers/net/ethernet/marvell/mvneta.c
> > @@ -4191,6 +4191,8 @@ static int mvneta_probe(struct platform_device *pdev)
> > clk_disable_unprepare(pp->clk);
> >  err_put_phy_node:
> > of_node_put(phy_node);
> > +   if (of_phy_is_fixed_link(dn))
> > +   of_phy_deregister_fixed_link(dn);
> 
> While building kernel Image for arm architecture on stable-rc 4.4 branch
> the following build error found.
> 
> drivers/net/ethernet/marvell/mvneta.c:3442:3: error: implicit
> declaration of function 'of_phy_deregister_fixed_link'; did you mean
> 'of_phy_register_fixed_link'? [-Werror=implicit-function-declaration]
> |of_phy_deregister_fixed_link(dn);
> |^~~~
> |of_phy_register_fixed_link
> 
> ref:
> https://gitlab.com/Linaro/lkft/kernel-runs/-/jobs/541374729

Greg, 3f65047c853a ("of_mdio: add helper to deregister fixed-link
PHYs") needs to be backported as well for these.

Original series can be found here:


https://lkml.kernel.org/r/1480357509-28074-1-git-send-email-jo...@kernel.org

Johan


[PATCH net 12/16] net: ethernet: mediatek: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on initialisation errors and on uninit.

Fixes: 0c72c50f6f93 ("net-next: mediatek: add fixed-phy support")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c 
b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 4a62ffd7729d..86a89cbd3ec9 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -318,6 +318,8 @@ static int mtk_phy_connect(struct net_device *dev)
return 0;
 
 err_phy:
+   if (of_phy_is_fixed_link(mac->of_node))
+   of_phy_deregister_fixed_link(mac->of_node);
of_node_put(np);
dev_err(eth->dev, "%s: invalid phy\n", __func__);
return -EINVAL;
@@ -1923,6 +1925,8 @@ static void mtk_uninit(struct net_device *dev)
struct mtk_eth *eth = mac->hw;
 
phy_disconnect(dev->phydev);
+   if (of_phy_is_fixed_link(mac->of_node))
+   of_phy_deregister_fixed_link(mac->of_node);
mtk_irq_disable(eth, MTK_QDMA_INT_MASK, ~0);
mtk_irq_disable(eth, MTK_PDMA_INT_MASK, ~0);
 }
-- 
2.7.3



[PATCH net 15/16] net: ethernet: ti: davinci_emac: fix fixed-link phydev and of-node leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Also remember to put the of-node reference on probe errors.

Fixes: 1bb6aa56bb38 ("net: davinci_emac: Add support for fixed-link
PHY")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/ti/davinci_emac.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ti/davinci_emac.c 
b/drivers/net/ethernet/ti/davinci_emac.c
index 84fbe5714f8b..481c7bf0395b 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1767,6 +1767,7 @@ static int davinci_emac_try_get_mac(struct 
platform_device *pdev,
  */
 static int davinci_emac_probe(struct platform_device *pdev)
 {
+   struct device_node *np = pdev->dev.of_node;
int rc = 0;
struct resource *res, *res_ctrl;
struct net_device *ndev;
@@ -1805,7 +1806,7 @@ static int davinci_emac_probe(struct platform_device 
*pdev)
if (!pdata) {
dev_err(>dev, "no platform data\n");
rc = -ENODEV;
-   goto no_pdata;
+   goto err_free_netdev;
}
 
/* MAC addr and PHY mask , RMII enable info from platform_data */
@@ -1941,6 +1942,10 @@ static int davinci_emac_probe(struct platform_device 
*pdev)
cpdma_chan_destroy(priv->rxchan);
cpdma_ctlr_destroy(priv->dma);
 no_pdata:
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
+   of_node_put(priv->phy_node);
+err_free_netdev:
free_netdev(ndev);
return rc;
 }
@@ -1956,6 +1961,7 @@ static int davinci_emac_remove(struct platform_device 
*pdev)
 {
struct net_device *ndev = platform_get_drvdata(pdev);
struct emac_priv *priv = netdev_priv(ndev);
+   struct device_node *np = pdev->dev.of_node;
 
dev_notice(>dev, "DaVinci EMAC: davinci_emac_remove()\n");
 
@@ -1968,6 +1974,8 @@ static int davinci_emac_remove(struct platform_device 
*pdev)
unregister_netdev(ndev);
of_node_put(priv->phy_node);
pm_runtime_disable(>dev);
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
free_netdev(ndev);
 
return 0;
-- 
2.7.3



[PATCH net 16/16] net: dsa: slave: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on slave-setup errors and on slave destroy.

Fixes: 0d8bcdd383b8 ("net: dsa: allow for more complex PHY setups")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 net/dsa/slave.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 2a5c20a13fe4..30e2e21d7619 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1177,6 +1177,8 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
ret = dsa_slave_phy_connect(p, slave_dev, p->port);
if (ret) {
netdev_err(slave_dev, "failed to connect to port %d: 
%d\n", p->port, ret);
+   if (phy_is_fixed)
+   of_phy_deregister_fixed_link(port_dn);
return ret;
}
}
@@ -1292,10 +1294,18 @@ int dsa_slave_create(struct dsa_switch *ds, struct 
device *parent,
 void dsa_slave_destroy(struct net_device *slave_dev)
 {
struct dsa_slave_priv *p = netdev_priv(slave_dev);
+   struct dsa_switch *ds = p->parent;
+   struct device_node *port_dn;
+
+   port_dn = ds->ports[p->port].dn;
 
netif_carrier_off(slave_dev);
-   if (p->phy)
+   if (p->phy) {
phy_disconnect(p->phy);
+
+   if (of_phy_is_fixed_link(port_dn))
+   of_phy_deregister_fixed_link(port_dn);
+   }
unregister_netdev(slave_dev);
free_netdev(slave_dev);
 }
-- 
2.7.3



[PATCH net 14/16] net: ethernet: dwc_eth_qos: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: 077742dac2c7 ("dwc_eth_qos: Add support for Synopsys DWC Ethernet
QoS")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/synopsys/dwc_eth_qos.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/synopsys/dwc_eth_qos.c 
b/drivers/net/ethernet/synopsys/dwc_eth_qos.c
index 4ba2421e625d..97d64bfed465 100644
--- a/drivers/net/ethernet/synopsys/dwc_eth_qos.c
+++ b/drivers/net/ethernet/synopsys/dwc_eth_qos.c
@@ -2881,7 +2881,7 @@ static int dwceqos_probe(struct platform_device *pdev)
ret = of_get_phy_mode(lp->pdev->dev.of_node);
if (ret < 0) {
dev_err(>pdev->dev, "error in getting phy i/f\n");
-   goto err_out_clk_dis_phy;
+   goto err_out_deregister_fixed_link;
}
 
lp->phy_interface = ret;
@@ -2889,14 +2889,14 @@ static int dwceqos_probe(struct platform_device *pdev)
ret = dwceqos_mii_init(lp);
if (ret) {
dev_err(>pdev->dev, "error in dwceqos_mii_init\n");
-   goto err_out_clk_dis_phy;
+   goto err_out_deregister_fixed_link;
}
 
ret = dwceqos_mii_probe(ndev);
if (ret != 0) {
netdev_err(ndev, "mii_probe fail.\n");
ret = -ENXIO;
-   goto err_out_clk_dis_phy;
+   goto err_out_deregister_fixed_link;
}
 
dwceqos_set_umac_addr(lp, lp->ndev->dev_addr, 0);
@@ -2914,7 +2914,7 @@ static int dwceqos_probe(struct platform_device *pdev)
if (ret) {
dev_err(>pdev->dev, "Unable to retrieve DT, error %d\n",
ret);
-   goto err_out_clk_dis_phy;
+   goto err_out_deregister_fixed_link;
}
dev_info(>pdev->dev, "pdev->id %d, baseaddr 0x%08lx, irq %d\n",
 pdev->id, ndev->base_addr, ndev->irq);
@@ -2924,7 +2924,7 @@ static int dwceqos_probe(struct platform_device *pdev)
if (ret) {
dev_err(>pdev->dev, "Unable to request IRQ %d, error %d\n",
ndev->irq, ret);
-   goto err_out_clk_dis_phy;
+   goto err_out_deregister_fixed_link;
}
 
if (netif_msg_probe(lp))
@@ -2935,11 +2935,14 @@ static int dwceqos_probe(struct platform_device *pdev)
ret = register_netdev(ndev);
if (ret) {
dev_err(>dev, "Cannot register net device, aborting.\n");
-   goto err_out_clk_dis_phy;
+   goto err_out_deregister_fixed_link;
}
 
return 0;
 
+err_out_deregister_fixed_link:
+   if (of_phy_is_fixed_link(pdev->dev.of_node))
+   of_phy_deregister_fixed_link(pdev->dev.of_node);
 err_out_clk_dis_phy:
clk_disable_unprepare(lp->phy_ref_clk);
 err_out_clk_dis_aper:
@@ -2959,8 +2962,11 @@ static int dwceqos_remove(struct platform_device *pdev)
if (ndev) {
lp = netdev_priv(ndev);
 
-   if (ndev->phydev)
+   if (ndev->phydev) {
phy_disconnect(ndev->phydev);
+   if (of_phy_is_fixed_link(pdev->dev.of_node))
+   of_phy_deregister_fixed_link(pdev->dev.of_node);
+   }
mdiobus_unregister(lp->mii_bus);
mdiobus_free(lp->mii_bus);
 
-- 
2.7.3



[PATCH net 13/16] net: ethernet: renesas: ravb: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on initialisation errors and on device
close after having disconnected the PHY.

Fixes: b4bc88a868ed ("ravb: Add fixed-link support")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/renesas/ravb_main.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c 
b/drivers/net/ethernet/renesas/ravb_main.c
index 630536bc72f9..f1f3be2cfe21 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1008,7 +1008,8 @@ static int ravb_phy_init(struct net_device *ndev)
of_node_put(pn);
if (!phydev) {
netdev_err(ndev, "failed to connect PHY\n");
-   return -ENOENT;
+   err = -ENOENT;
+   goto err_deregister_fixed_link;
}
 
/* This driver only support 10/100Mbit speeds on Gen3
@@ -1020,8 +1021,7 @@ static int ravb_phy_init(struct net_device *ndev)
err = phy_set_max_speed(phydev, SPEED_100);
if (err) {
netdev_err(ndev, "failed to limit PHY to 100Mbit/s\n");
-   phy_disconnect(phydev);
-   return err;
+   goto err_phy_disconnect;
}
 
netdev_info(ndev, "limited PHY to 100Mbit/s\n");
@@ -1033,6 +1033,14 @@ static int ravb_phy_init(struct net_device *ndev)
phy_attached_info(phydev);
 
return 0;
+
+err_phy_disconnect:
+   phy_disconnect(phydev);
+err_deregister_fixed_link:
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
+
+   return err;
 }
 
 /* PHY control start function */
@@ -1634,6 +1642,7 @@ static void ravb_set_rx_mode(struct net_device *ndev)
 /* Device close function for Ethernet AVB */
 static int ravb_close(struct net_device *ndev)
 {
+   struct device_node *np = ndev->dev.parent->of_node;
struct ravb_private *priv = netdev_priv(ndev);
struct ravb_tstamp_skb *ts_skb, *ts_skb2;
 
@@ -1663,6 +1672,8 @@ static int ravb_close(struct net_device *ndev)
if (ndev->phydev) {
phy_stop(ndev->phydev);
phy_disconnect(ndev->phydev);
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
}
 
if (priv->chip_id != RCAR_GEN2) {
-- 
2.7.3



[PATCH net 08/16] net: ethernet: fs_enet: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: bb74d9a4a87b ("fs_enet: use the new fixed PHY helpers")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c 
b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index dc120c148d97..4b86260584a0 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -980,7 +980,7 @@ static int fs_enet_probe(struct platform_device *ofdev)
err = clk_prepare_enable(clk);
if (err) {
ret = err;
-   goto out_free_fpi;
+   goto out_deregister_fixed_link;
}
fpi->clk_per = clk;
}
@@ -1061,6 +1061,9 @@ static int fs_enet_probe(struct platform_device *ofdev)
of_node_put(fpi->phy_node);
if (fpi->clk_per)
clk_disable_unprepare(fpi->clk_per);
+out_deregister_fixed_link:
+   if (of_phy_is_fixed_link(ofdev->dev.of_node))
+   of_phy_deregister_fixed_link(ofdev->dev.of_node);
 out_free_fpi:
kfree(fpi);
return ret;
@@ -1079,6 +1082,8 @@ static int fs_enet_remove(struct platform_device *ofdev)
of_node_put(fep->fpi->phy_node);
if (fep->fpi->clk_per)
clk_disable_unprepare(fep->fpi->clk_per);
+   if (of_phy_is_fixed_link(ofdev->dev.of_node))
+   of_phy_deregister_fixed_link(ofdev->dev.of_node);
free_netdev(ndev);
return 0;
 }
-- 
2.7.3



[PATCH net 10/16] net: ethernet: ucc_geth: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: 87009814cdbb ("ucc_geth: use the new fixed PHY helpers")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/freescale/ucc_geth.c | 23 ---
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/freescale/ucc_geth.c 
b/drivers/net/ethernet/freescale/ucc_geth.c
index 186ef8f16c80..f76d33279454 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -3868,9 +3868,8 @@ static int ucc_geth_probe(struct platform_device* ofdev)
dev = alloc_etherdev(sizeof(*ugeth));
 
if (dev == NULL) {
-   of_node_put(ug_info->tbi_node);
-   of_node_put(ug_info->phy_node);
-   return -ENOMEM;
+   err = -ENOMEM;
+   goto err_deregister_fixed_link;
}
 
ugeth = netdev_priv(dev);
@@ -3907,10 +3906,7 @@ static int ucc_geth_probe(struct platform_device* ofdev)
if (netif_msg_probe(ugeth))
pr_err("%s: Cannot register net device, aborting\n",
   dev->name);
-   free_netdev(dev);
-   of_node_put(ug_info->tbi_node);
-   of_node_put(ug_info->phy_node);
-   return err;
+   goto err_free_netdev;
}
 
mac_addr = of_get_mac_address(np);
@@ -3923,16 +3919,29 @@ static int ucc_geth_probe(struct platform_device* ofdev)
ugeth->node = np;
 
return 0;
+
+err_free_netdev:
+   free_netdev(dev);
+err_deregister_fixed_link:
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
+   of_node_put(ug_info->tbi_node);
+   of_node_put(ug_info->phy_node);
+
+   return err;
 }
 
 static int ucc_geth_remove(struct platform_device* ofdev)
 {
struct net_device *dev = platform_get_drvdata(ofdev);
struct ucc_geth_private *ugeth = netdev_priv(dev);
+   struct device_node *np = ofdev->dev.of_node;
 
unregister_netdev(dev);
free_netdev(dev);
ucc_geth_memclean(ugeth);
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
of_node_put(ugeth->ug_info->tbi_node);
of_node_put(ugeth->ug_info->phy_node);
 
-- 
2.7.3



[PATCH net 07/16] net: ethernet: fec: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: 407066f8f371 ("net: fec: Support phys probed from devicetree and
fixed-link")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/freescale/fec_main.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index 5aa9d4ded214..74dcdf097348 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3475,6 +3475,8 @@ fec_probe(struct platform_device *pdev)
 failed_clk_ipg:
fec_enet_clk_enable(ndev, false);
 failed_clk:
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
 failed_phy:
of_node_put(phy_node);
 failed_ioremap:
@@ -3488,6 +3490,7 @@ fec_drv_remove(struct platform_device *pdev)
 {
struct net_device *ndev = platform_get_drvdata(pdev);
struct fec_enet_private *fep = netdev_priv(ndev);
+   struct device_node *np = pdev->dev.of_node;
 
cancel_work_sync(>tx_timeout_work);
fec_ptp_stop(pdev);
@@ -3495,6 +3498,8 @@ fec_drv_remove(struct platform_device *pdev)
fec_enet_mii_remove(fep);
if (fep->reg_phy)
regulator_disable(fep->reg_phy);
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
of_node_put(fep->phy_node);
free_netdev(ndev);
 
-- 
2.7.3



[PATCH net 11/16] net: ethernet: marvell: mvneta: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: 83895bedeee6 ("net: mvneta: add support for fixed links")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/marvell/mvneta.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvneta.c 
b/drivers/net/ethernet/marvell/mvneta.c
index 0c0a45af950f..707bc4680b9b 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -4191,6 +4191,8 @@ static int mvneta_probe(struct platform_device *pdev)
clk_disable_unprepare(pp->clk);
 err_put_phy_node:
of_node_put(phy_node);
+   if (of_phy_is_fixed_link(dn))
+   of_phy_deregister_fixed_link(dn);
 err_free_irq:
irq_dispose_mapping(dev->irq);
 err_free_netdev:
@@ -4202,6 +4204,7 @@ static int mvneta_probe(struct platform_device *pdev)
 static int mvneta_remove(struct platform_device *pdev)
 {
struct net_device  *dev = platform_get_drvdata(pdev);
+   struct device_node *dn = pdev->dev.of_node;
struct mvneta_port *pp = netdev_priv(dev);
 
unregister_netdev(dev);
@@ -4209,6 +4212,8 @@ static int mvneta_remove(struct platform_device *pdev)
clk_disable_unprepare(pp->clk);
free_percpu(pp->ports);
free_percpu(pp->stats);
+   if (of_phy_is_fixed_link(dn))
+   of_phy_deregister_fixed_link(dn);
irq_dispose_mapping(dev->irq);
of_node_put(pp->phy_node);
free_netdev(dev);
-- 
2.7.3



[PATCH net 06/16] net: ethernet: bcmgenet: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Note that we're still leaking any fixed-link PHY registered in the
non-OF probe path.

Fixes: 9abf0c2b717a ("net: bcmgenet: use the new fixed PHY helpers")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/broadcom/genet/bcmmii.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c 
b/drivers/net/ethernet/broadcom/genet/bcmmii.c
index 2e745bd51df4..e87607621e62 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
@@ -627,6 +627,7 @@ static int bcmgenet_mii_bus_init(struct bcmgenet_priv *priv)
 int bcmgenet_mii_init(struct net_device *dev)
 {
struct bcmgenet_priv *priv = netdev_priv(dev);
+   struct device_node *dn = priv->pdev->dev.of_node;
int ret;
 
ret = bcmgenet_mii_alloc(priv);
@@ -640,6 +641,8 @@ int bcmgenet_mii_init(struct net_device *dev)
return 0;
 
 out:
+   if (of_phy_is_fixed_link(dn))
+   of_phy_deregister_fixed_link(dn);
of_node_put(priv->phy_dn);
mdiobus_unregister(priv->mii_bus);
mdiobus_free(priv->mii_bus);
@@ -649,7 +652,10 @@ int bcmgenet_mii_init(struct net_device *dev)
 void bcmgenet_mii_exit(struct net_device *dev)
 {
struct bcmgenet_priv *priv = netdev_priv(dev);
+   struct device_node *dn = priv->pdev->dev.of_node;
 
+   if (of_phy_is_fixed_link(dn))
+   of_phy_deregister_fixed_link(dn);
of_node_put(priv->phy_dn);
mdiobus_unregister(priv->mii_bus);
mdiobus_free(priv->mii_bus);
-- 
2.7.3



[PATCH net 09/16] net: ethernet: gianfar: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: be40364544bd ("gianfar: use the new fixed PHY helpers")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/freescale/gianfar.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/freescale/gianfar.c 
b/drivers/net/ethernet/freescale/gianfar.c
index 4b4f5bc0e279..9061c2f82b9c 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -1312,6 +1312,7 @@ static void gfar_init_addr_hash_table(struct gfar_private 
*priv)
  */
 static int gfar_probe(struct platform_device *ofdev)
 {
+   struct device_node *np = ofdev->dev.of_node;
struct net_device *dev = NULL;
struct gfar_private *priv = NULL;
int err = 0, i;
@@ -1462,6 +1463,8 @@ static int gfar_probe(struct platform_device *ofdev)
return 0;
 
 register_fail:
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
unmap_group_regs(priv);
gfar_free_rx_queues(priv);
gfar_free_tx_queues(priv);
@@ -1474,11 +1477,16 @@ static int gfar_probe(struct platform_device *ofdev)
 static int gfar_remove(struct platform_device *ofdev)
 {
struct gfar_private *priv = platform_get_drvdata(ofdev);
+   struct device_node *np = ofdev->dev.of_node;
 
of_node_put(priv->phy_node);
of_node_put(priv->tbi_node);
 
unregister_netdev(priv->ndev);
+
+   if (of_phy_is_fixed_link(np))
+   of_phy_deregister_fixed_link(np);
+
unmap_group_regs(priv);
gfar_free_rx_queues(priv);
gfar_free_tx_queues(priv);
-- 
2.7.3



[PATCH net 05/16] net: ethernet: bcmsysport: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: 186534a3f832 ("net: systemport: use the new fixed PHY helpers")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/broadcom/bcmsysport.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c 
b/drivers/net/ethernet/broadcom/bcmsysport.c
index c3354b9941d1..25d1eb4933d0 100644
--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1755,13 +1755,13 @@ static int bcm_sysport_probe(struct platform_device 
*pdev)
if (priv->irq0 <= 0 || priv->irq1 <= 0) {
dev_err(>dev, "invalid interrupts\n");
ret = -EINVAL;
-   goto err;
+   goto err_free_netdev;
}
 
priv->base = devm_ioremap_resource(>dev, r);
if (IS_ERR(priv->base)) {
ret = PTR_ERR(priv->base);
-   goto err;
+   goto err_free_netdev;
}
 
priv->netdev = dev;
@@ -1779,7 +1779,7 @@ static int bcm_sysport_probe(struct platform_device *pdev)
ret = of_phy_register_fixed_link(dn);
if (ret) {
dev_err(>dev, "failed to register fixed PHY\n");
-   goto err;
+   goto err_free_netdev;
}
 
priv->phy_dn = dn;
@@ -1821,7 +1821,7 @@ static int bcm_sysport_probe(struct platform_device *pdev)
ret = register_netdev(dev);
if (ret) {
dev_err(>dev, "failed to register net_device\n");
-   goto err;
+   goto err_deregister_fixed_link;
}
 
priv->rev = topctrl_readl(priv, REV_CNTL) & REV_MASK;
@@ -1832,7 +1832,11 @@ static int bcm_sysport_probe(struct platform_device 
*pdev)
 priv->base, priv->irq0, priv->irq1, txq, rxq);
 
return 0;
-err:
+
+err_deregister_fixed_link:
+   if (of_phy_is_fixed_link(dn))
+   of_phy_deregister_fixed_link(dn);
+err_free_netdev:
free_netdev(dev);
return ret;
 }
@@ -1840,11 +1844,14 @@ static int bcm_sysport_probe(struct platform_device 
*pdev)
 static int bcm_sysport_remove(struct platform_device *pdev)
 {
struct net_device *dev = dev_get_drvdata(>dev);
+   struct device_node *dn = pdev->dev.of_node;
 
/* Not much to do, ndo_close has been called
 * and we use managed allocations
 */
unregister_netdev(dev);
+   if (of_phy_is_fixed_link(dn))
+   of_phy_deregister_fixed_link(dn);
free_netdev(dev);
dev_set_drvdata(>dev, NULL);
 
-- 
2.7.3



[PATCH net 04/16] net: ethernet: aurora: nb8800: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: c7dfe3abf40e ("net: ethernet: nb8800: support fixed-link DT
node")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/aurora/nb8800.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/aurora/nb8800.c 
b/drivers/net/ethernet/aurora/nb8800.c
index 00c38bf151e6..e078d8da978c 100644
--- a/drivers/net/ethernet/aurora/nb8800.c
+++ b/drivers/net/ethernet/aurora/nb8800.c
@@ -1466,12 +1466,12 @@ static int nb8800_probe(struct platform_device *pdev)
 
ret = nb8800_hw_init(dev);
if (ret)
-   goto err_free_bus;
+   goto err_deregister_fixed_link;
 
if (ops && ops->init) {
ret = ops->init(dev);
if (ret)
-   goto err_free_bus;
+   goto err_deregister_fixed_link;
}
 
dev->netdev_ops = _netdev_ops;
@@ -1504,6 +1504,9 @@ static int nb8800_probe(struct platform_device *pdev)
 
 err_free_dma:
nb8800_dma_free(dev);
+err_deregister_fixed_link:
+   if (of_phy_is_fixed_link(pdev->dev.of_node))
+   of_phy_deregister_fixed_link(pdev->dev.of_node);
 err_free_bus:
of_node_put(priv->phy_node);
mdiobus_unregister(bus);
@@ -1521,6 +1524,8 @@ static int nb8800_remove(struct platform_device *pdev)
struct nb8800_priv *priv = netdev_priv(ndev);
 
unregister_netdev(ndev);
+   if (of_phy_is_fixed_link(pdev->dev.of_node))
+   of_phy_deregister_fixed_link(pdev->dev.of_node);
of_node_put(priv->phy_node);
 
mdiobus_unregister(priv->mii_bus);
-- 
2.7.3



[PATCH net 01/16] net: dsa: slave: fix of-node leak and phy priority

2016-11-28 Thread Johan Hovold
Make sure to drop the reference taken by of_parse_phandle() before
returning from dsa_slave_phy_setup().

Note that this also modifies the PHY priority so that any fixed-link
node is only parsed when no phy-handle is given, which is in accordance
with the common scheme for this.

Fixes: 0d8bcdd383b8 ("net: dsa: allow for more complex PHY setups")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 net/dsa/slave.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 6b1282c006b1..2a5c20a13fe4 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1125,7 +1125,7 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
p->phy_interface = mode;
 
phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
-   if (of_phy_is_fixed_link(port_dn)) {
+   if (!phy_dn && of_phy_is_fixed_link(port_dn)) {
/* In the case of a fixed PHY, the DT node associated
 * to the fixed PHY is the Port DT node
 */
@@ -1135,7 +1135,7 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
return ret;
}
phy_is_fixed = true;
-   phy_dn = port_dn;
+   phy_dn = of_node_get(port_dn);
}
 
if (ds->ops->get_phy_flags)
@@ -1154,6 +1154,7 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
ret = dsa_slave_phy_connect(p, slave_dev, phy_id);
if (ret) {
netdev_err(slave_dev, "failed to connect to 
phy%d: %d\n", phy_id, ret);
+   of_node_put(phy_dn);
return ret;
}
} else {
@@ -1162,6 +1163,8 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
phy_flags,
p->phy_interface);
}
+
+   of_node_put(phy_dn);
}
 
if (p->phy && phy_is_fixed)
-- 
2.7.3



[PATCH net 02/16] of_mdio: add helper to deregister fixed-link PHYs

2016-11-28 Thread Johan Hovold
Add helper to deregister fixed-link PHYs registered using
of_phy_register_fixed_link().

Convert the two drivers that care to deregister their fixed-link PHYs to
use the new helper, but note that most drivers currently fail to do so.

Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/ti/cpsw.c | 16 ++--
 drivers/of/of_mdio.c   | 15 +++
 include/linux/of_mdio.h|  4 
 net/dsa/dsa.c  | 12 ++--
 4 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 58947aae31c7..9f0646512624 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -2459,20 +2459,8 @@ static void cpsw_remove_dt(struct platform_device *pdev)
if (strcmp(slave_node->name, "slave"))
continue;
 
-   if (of_phy_is_fixed_link(slave_node)) {
-   struct phy_device *phydev;
-
-   phydev = of_phy_find_device(slave_node);
-   if (phydev) {
-   fixed_phy_unregister(phydev);
-   /* Put references taken by
-* of_phy_find_device() and
-* of_phy_register_fixed_link().
-*/
-   phy_device_free(phydev);
-   phy_device_free(phydev);
-   }
-   }
+   if (of_phy_is_fixed_link(slave_node))
+   of_phy_deregister_fixed_link(slave_node);
 
of_node_put(slave_data->phy_node);
 
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 5a3145a02547..262281bd68fa 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -490,3 +490,18 @@ int of_phy_register_fixed_link(struct device_node *np)
return -ENODEV;
 }
 EXPORT_SYMBOL(of_phy_register_fixed_link);
+
+void of_phy_deregister_fixed_link(struct device_node *np)
+{
+   struct phy_device *phydev;
+
+   phydev = of_phy_find_device(np);
+   if (!phydev)
+   return;
+
+   fixed_phy_unregister(phydev);
+
+   put_device(>mdio.dev);  /* of_phy_find_device() */
+   phy_device_free(phydev);/* fixed_phy_register() */
+}
+EXPORT_SYMBOL(of_phy_deregister_fixed_link);
diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h
index 2ab233661ae5..a58cca8bcb29 100644
--- a/include/linux/of_mdio.h
+++ b/include/linux/of_mdio.h
@@ -29,6 +29,7 @@ struct phy_device *of_phy_attach(struct net_device *dev,
 extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
 extern int of_mdio_parse_addr(struct device *dev, const struct device_node 
*np);
 extern int of_phy_register_fixed_link(struct device_node *np);
+extern void of_phy_deregister_fixed_link(struct device_node *np);
 extern bool of_phy_is_fixed_link(struct device_node *np);
 
 #else /* CONFIG_OF */
@@ -83,6 +84,9 @@ static inline int of_phy_register_fixed_link(struct 
device_node *np)
 {
return -ENOSYS;
 }
+static inline void of_phy_deregister_fixed_link(struct device_node *np)
+{
+}
 static inline bool of_phy_is_fixed_link(struct device_node *np)
 {
return false;
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index cb0091b99592..7899919cd9f0 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -506,16 +506,8 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
 
 void dsa_cpu_dsa_destroy(struct device_node *port_dn)
 {
-   struct phy_device *phydev;
-
-   if (of_phy_is_fixed_link(port_dn)) {
-   phydev = of_phy_find_device(port_dn);
-   if (phydev) {
-   fixed_phy_unregister(phydev);
-   put_device(>mdio.dev);
-   phy_device_free(phydev);
-   }
-   }
+   if (of_phy_is_fixed_link(port_dn))
+   of_phy_deregister_fixed_link(port_dn);
 }
 
 static void dsa_switch_destroy(struct dsa_switch *ds)
-- 
2.7.3



[PATCH net 00/16] net: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
This series fixes failures to deregister and free fixed-link phydevs
that have been registered using the of_phy_register_fixed_link()
interface.

All but two drivers currently fail to do this and this series fixes most
of them with the exception of a staging driver and the stmmac drivers
which will be fixed by follow-on patches.

Included are also a couple of fixes for related of-node leaks.

Note that all patches except the of_mdio one have been compile-tested
only.

Also note that the series is against net due to dependencies not yet in
net-next.

Johan


Johan Hovold (16):
  net: dsa: slave: fix of-node leak and phy priority
  of_mdio: add helper to deregister fixed-link PHYs
  net: ethernet: altera: fix fixed-link phydev leaks
  net: ethernet: aurora: nb8800: fix fixed-link phydev leaks
  net: ethernet: bcmsysport: fix fixed-link phydev leaks
  net: ethernet: bcmgenet: fix fixed-link phydev leaks
  net: ethernet: fec: fix fixed-link phydev leaks
  net: ethernet: fs_enet: fix fixed-link phydev leaks
  net: ethernet: gianfar: fix fixed-link phydev leaks
  net: ethernet: ucc_geth: fix fixed-link phydev leaks
  net: ethernet: marvell: mvneta: fix fixed-link phydev leaks
  net: ethernet: mediatek: fix fixed-link phydev leaks
  net: ethernet: renesas: ravb: fix fixed-link phydev leaks
  net: ethernet: dwc_eth_qos: fix fixed-link phydev leaks
  net: ethernet: ti: davinci_emac: fix fixed-link phydev and of-node
leaks
  net: dsa: slave: fix fixed-link phydev leaks

 drivers/net/ethernet/altera/altera_tse_main.c  |  9 -
 drivers/net/ethernet/aurora/nb8800.c   |  9 +++--
 drivers/net/ethernet/broadcom/bcmsysport.c | 17 +++-
 drivers/net/ethernet/broadcom/genet/bcmmii.c   |  6 ++
 drivers/net/ethernet/freescale/fec_main.c  |  5 +
 .../net/ethernet/freescale/fs_enet/fs_enet-main.c  |  7 ++-
 drivers/net/ethernet/freescale/gianfar.c   |  8 
 drivers/net/ethernet/freescale/ucc_geth.c  | 23 +++---
 drivers/net/ethernet/marvell/mvneta.c  |  5 +
 drivers/net/ethernet/mediatek/mtk_eth_soc.c|  4 
 drivers/net/ethernet/renesas/ravb_main.c   | 17 +---
 drivers/net/ethernet/synopsys/dwc_eth_qos.c| 20 ---
 drivers/net/ethernet/ti/cpsw.c | 16 ++-
 drivers/net/ethernet/ti/davinci_emac.c | 10 +-
 drivers/of/of_mdio.c   | 15 ++
 include/linux/of_mdio.h|  4 
 net/dsa/dsa.c  | 12 ++-
 net/dsa/slave.c| 19 +++---
 18 files changed, 152 insertions(+), 54 deletions(-)

-- 
2.7.3



[PATCH net 03/16] net: ethernet: altera: fix fixed-link phydev leaks

2016-11-28 Thread Johan Hovold
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: 7cdbc6f74f8e ("altera tse: add support for fixed-links.")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/net/ethernet/altera/altera_tse_main.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/altera/altera_tse_main.c 
b/drivers/net/ethernet/altera/altera_tse_main.c
index bda31f308cc2..6532829b70d2 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -819,6 +819,8 @@ static int init_phy(struct net_device *dev)
 
if (!phydev) {
netdev_err(dev, "Could not find the PHY\n");
+   if (fixed_link)
+   of_phy_deregister_fixed_link(priv->device->of_node);
return -ENODEV;
}
 
@@ -1545,10 +1547,15 @@ static int altera_tse_probe(struct platform_device 
*pdev)
 static int altera_tse_remove(struct platform_device *pdev)
 {
struct net_device *ndev = platform_get_drvdata(pdev);
+   struct altera_tse_private *priv = netdev_priv(ndev);
 
-   if (ndev->phydev)
+   if (ndev->phydev) {
phy_disconnect(ndev->phydev);
 
+   if (of_phy_is_fixed_link(priv->device->of_node))
+   of_phy_deregister_fixed_link(priv->device->of_node);
+   }
+
platform_set_drvdata(pdev, NULL);
altera_tse_mdio_destroy(ndev);
unregister_netdev(ndev);
-- 
2.7.3



[PATCH 3/4] powerpc/vio: clarify vio_find_node reference counting

2016-11-01 Thread Johan Hovold
Add comment clarifying that vio_find_node() takes a reference to the
embedded struct device which needs to be dropped after use.

Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 arch/powerpc/kernel/vio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index b3813ddb2fb4..2c8fb3ec989e 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1648,6 +1648,9 @@ static struct vio_dev *vio_find_name(const char *name)
 /**
  * vio_find_node - find an already-registered vio_dev
  * @vnode: device_node of the virtual device we're looking for
+ *
+ * Takes a reference to the embedded struct device which needs to be dropped
+ * after use.
  */
 struct vio_dev *vio_find_node(struct device_node *vnode)
 {
-- 
2.7.3



[PATCH 4/4] powerpc/pci: fix device reference leaks

2016-11-01 Thread Johan Hovold
Make sure to drop any device reference taken by vio_find_node() when
adding and removing virtual I/O slots.

Fixes: 5eeb8c63a38f ("[PATCH] PCI Hotplug: rpaphp: Move VIO...")
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 drivers/pci/hotplug/rpadlpar_core.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/hotplug/rpadlpar_core.c 
b/drivers/pci/hotplug/rpadlpar_core.c
index dc67f39779ec..c614ff7c3bc3 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -257,8 +257,13 @@ static int dlpar_add_phb(char *drc_name, struct 
device_node *dn)
 
 static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
 {
-   if (vio_find_node(dn))
+   struct vio_dev *vio_dev;
+
+   vio_dev = vio_find_node(dn);
+   if (vio_dev) {
+   put_device(_dev->dev);
return -EINVAL;
+   }
 
if (!vio_register_device_node(dn)) {
printk(KERN_ERR
@@ -334,6 +339,9 @@ static int dlpar_remove_vio_slot(char *drc_name, struct 
device_node *dn)
return -EINVAL;
 
vio_unregister_device(vio_dev);
+
+   put_device(_dev->dev);
+
return 0;
 }
 
-- 
2.7.3



[PATCH 2/4] ibmebus: fix further device reference leaks

2016-11-01 Thread Johan Hovold
Make sure to drop any reference taken by bus_find_device() when creating
devices during init and driver registration.

Fixes: 55347cc9962f ("[POWERPC] ibmebus: Add device creation...)
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 arch/powerpc/kernel/ibmebus.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index c7d3ff7e101c..35f5244782d9 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -180,6 +180,7 @@ static int ibmebus_create_device(struct device_node *dn)
 static int ibmebus_create_devices(const struct of_device_id *matches)
 {
struct device_node *root, *child;
+   struct device *dev;
int ret = 0;
 
root = of_find_node_by_path("/");
@@ -188,9 +189,12 @@ static int ibmebus_create_devices(const struct 
of_device_id *matches)
if (!of_match_node(matches, child))
continue;
 
-   if (bus_find_device(_bus_type, NULL, child,
-   ibmebus_match_node))
+   dev = bus_find_device(_bus_type, NULL, child,
+ ibmebus_match_node);
+   if (dev) {
+   put_device(dev);
continue;
+   }
 
ret = ibmebus_create_device(child);
if (ret) {
-- 
2.7.3



[PATCH 1/4] ibmebus: fix device reference leaks in sysfs interface

2016-11-01 Thread Johan Hovold
Make sure to drop any reference taken by bus_find_device() in the sysfs
callbacks that are used to create and destroy devices based on
device-tree entries.

Fixes: 6bccf755ff53 ("[POWERPC] ibmebus: dynamic addition/removal...)
Signed-off-by: Johan Hovold <jo...@kernel.org>
---
 arch/powerpc/kernel/ibmebus.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index 6ca9a2ffaac7..c7d3ff7e101c 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -262,6 +262,7 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus,
   const char *buf, size_t count)
 {
struct device_node *dn = NULL;
+   struct device *dev;
char *path;
ssize_t rc = 0;
 
@@ -269,8 +270,10 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus,
if (!path)
return -ENOMEM;
 
-   if (bus_find_device(_bus_type, NULL, path,
-   ibmebus_match_path)) {
+   dev = bus_find_device(_bus_type, NULL, path,
+ ibmebus_match_path);
+   if (dev) {
+   put_device(dev);
printk(KERN_WARNING "%s: %s has already been probed\n",
   __func__, path);
rc = -EEXIST;
@@ -307,6 +310,7 @@ static ssize_t ibmebus_store_remove(struct bus_type *bus,
if ((dev = bus_find_device(_bus_type, NULL, path,
   ibmebus_match_path))) {
of_device_unregister(to_platform_device(dev));
+   put_device(dev);
 
kfree(path);
return count;
-- 
2.7.3