diff mbox series

clk/meson: fixes memleak issue in init err branch

Message ID 20200429031416.3900-1-bernard@vivo.com (mailing list archive)
State Not Applicable
Delegated to: Neil Armstrong
Headers show
Series clk/meson: fixes memleak issue in init err branch | expand

Commit Message

Bernard Zhao April 29, 2020, 3:14 a.m. UTC
In common init function, when run into err branch, we didn`t
use kfree to release kzmalloc area, this may bring in memleak

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 drivers/clk/meson/meson8b.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Jerome Brunet April 29, 2020, 12:37 p.m. UTC | #1
On Wed 29 Apr 2020 at 05:14, Bernard Zhao <bernard@vivo.com> wrote:

> In common init function, when run into err branch, we didn`t
> use kfree to release kzmalloc area, this may bring in memleak

Thx for reporting this Bernard.
I'm not a fan of adding kfree everywhere. I'd much prefer a label and
clear error exit path.

That being said, the allocation is probably not the only thing that
needs to be undone in case of error. I guess this is due to conversion
to CLK_OF_DECLARE_DRIVER() which forced to drop all the devm_
This was done because the clock controller was required early in the
boot sequence.

There is 2 paths to properly solve this:
1) Old school: manually undo everything with every error exit condition
   Doable but probably a bit messy
2) Convert back the driver to a real platform driver and use devm_.
   We would still need the controller to register early but I wonder if
   we could use the same method as drivers/clk/mediatek/clk-mt2701.c and
   use arch_initcall() ?

Martin, you did the initial conversion, what do you think of option 2 ?
Would it still answer the problem you were trying to solve back then ?

One added benefit of option 2 is we could drop CLK_OF_DECLARE_DRIVER().
We could even do the same in for the other SoCs, which I suppose would
avoid a fair amount of probe deferral.

>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  drivers/clk/meson/meson8b.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
> index 34a70c4b4899..0f07d5a4cd16 100644
> --- a/drivers/clk/meson/meson8b.c
> +++ b/drivers/clk/meson/meson8b.c
> @@ -3687,6 +3687,7 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
>  	if (ret) {
>  		pr_err("%s: Failed to register clkc reset controller: %d\n",
>  		       __func__, ret);
> +		kfree(rstc);
>  		return;
>  	}
>  
> @@ -3710,8 +3711,10 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
>  			continue;
>  
>  		ret = of_clk_hw_register(np, clk_hw_onecell_data->hws[i]);
> -		if (ret)
> +		if (ret) {
> +			kfree(rstc);
>  			return;
> +		}
>  	}
>  
>  	meson8b_cpu_nb_data.cpu_clk = clk_hw_onecell_data->hws[CLKID_CPUCLK];
> @@ -3727,13 +3730,16 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
>  	if (ret) {
>  		pr_err("%s: failed to register the CPU clock notifier\n",
>  		       __func__);
> +		kfree(rstc);
>  		return;
>  	}
>  
>  	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get,
>  				     clk_hw_onecell_data);
> -	if (ret)
> +	if (ret) {
>  		pr_err("%s: failed to register clock provider\n", __func__);
> +		kfree(rstc);
> +	}
>  }
>  
>  static void __init meson8_clkc_init(struct device_node *np)
Martin Blumenstingl April 29, 2020, 5:43 p.m. UTC | #2
Hi Jerome,

On Wed, Apr 29, 2020 at 2:37 PM Jerome Brunet <jbrunet@baylibre.com> wrote:
>
>
> On Wed 29 Apr 2020 at 05:14, Bernard Zhao <bernard@vivo.com> wrote:
>
> > In common init function, when run into err branch, we didn`t
> > use kfree to release kzmalloc area, this may bring in memleak
>
> Thx for reporting this Bernard.
> I'm not a fan of adding kfree everywhere. I'd much prefer a label and
> clear error exit path.
>
> That being said, the allocation is probably not the only thing that
> needs to be undone in case of error. I guess this is due to conversion
> to CLK_OF_DECLARE_DRIVER() which forced to drop all the devm_
> This was done because the clock controller was required early in the
> boot sequence.
>
> There is 2 paths to properly solve this:
> 1) Old school: manually undo everything with every error exit condition
>    Doable but probably a bit messy
> 2) Convert back the driver to a real platform driver and use devm_.
>    We would still need the controller to register early but I wonder if
>    we could use the same method as drivers/clk/mediatek/clk-mt2701.c and
>    use arch_initcall() ?
>
> Martin, you did the initial conversion, what do you think of option 2 ?
I tried it with the attached patch
unfortunately my "m8b_clkc_test_probe" is still run too late

> Would it still answer the problem you were trying to solve back then ?
I'm afraid it does not:
- the resets are needed early for SMP initialization
- the clocks are needed even earlier for timer registration (we have
both, the ARM TWD timer and some Amlogic custom timer. both have clock
inputs)

> One added benefit of option 2 is we could drop CLK_OF_DECLARE_DRIVER().
> We could even do the same in for the other SoCs, which I suppose would
> avoid a fair amount of probe deferral.
it would be great, indeed
but this will only work once timer initialization and SMP boot can
happen at a later stage

If the clock controller registration fails the board won't boot. Yes,
cleaning up memory is good, but in this specific case it will add a
couple of extra CPU cycles before the kernel is dead
So, if we want to ignore that fact then I agree with your first option
(undoing things the "old school" way).


Martin
[    0.000000] Booting Linux on physical CPU 0x200
[    0.000000] Linux version 5.7.0-rc3-00142-g0be442fc16c8-dirty (xdarklight@blackbox) (gcc version 9.3.0 (Arch Repository), GNU ld (GNU Binutils) 2.34) #6397 SMP PREEMPT Wed Apr 29 19:32:07 CEST 2020
[    0.000000] CPU: ARMv7 Processor [410fc051] revision 1 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: Endless Computers Endless Mini
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 64 MiB at 0x7c000000
[    0.000000] percpu: Embedded 16 pages/cpu s34824 r8192 d22520 u65536
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 522052
[    0.000000] Kernel command line: console=ttyAML0,115200 root=/dev/sda1 rw
[    0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, linear)
[    0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 1965696K/2095104K available (18432K kernel code, 727K rwdata, 6820K rodata, 1024K init, 958K bss, 63872K reserved, 65536K cma-reserved, 1245184K highmem)
[    0.000000] random: get_random_u32 called from __kmem_cache_create+0x28/0x38c with crng_init=0
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
[    0.000000]  Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000000] irq_meson_gpio: 119 to 8 gpio interrupt mux initialized
[    0.000000] L2C: DT/platform modifies aux control register: 0x02060000 -> 0x02460000
[    0.000000] L2C-310 erratum 769419 enabled
[    0.000000] L2C-310 ID prefetch enabled, offset 1 lines
[    0.000000] L2C-310 dynamic clock gating enabled, standby mode enabled
[    0.000000] L2C-310 cache controller enabled, 8 ways, 512 kB
[    0.000000] L2C-310: CACHE_ID 0x4100a0c9, AUX_CTRL 0x36460000
[    0.000020] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
[    0.000048] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.000097] Switching to timer-based delay loop, resolution 1000ns
[    0.000913] Console: colour dummy device 80x30
[    0.000970] Calibrating delay loop (skipped), value calculated using timer frequency.. 2.00 BogoMIPS (lpj=4000)
[    0.000989] pid_max: default: 32768 minimum: 301
[    0.001362] LSM: Security Framework initializing
[    0.001696] Smack:  Initializing.
[    0.001706] Smack:  IPv6 port labeling enabled.
[    0.001934] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[    0.001958] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[    0.003392] CPU: Testing write buffer coherency: ok
[    0.003787] CPU0: thread -1, cpu 0, socket 2, mpidr 80000200
[    0.005247] Setting up static identity map for 0x300000 - 0x300060
[    0.005509] rcu: Hierarchical SRCU implementation.
[    0.006663] smp: Bringing up secondary CPUs ...
[    0.007782] CPU1: thread -1, cpu 1, socket 2, mpidr 80000201
[    0.009161] CPU2: thread -1, cpu 2, socket 2, mpidr 80000202
[    0.010384] CPU3: thread -1, cpu 3, socket 2, mpidr 80000203
[    0.010573] smp: Brought up 1 node, 4 CPUs
[    0.010599] SMP: Total of 4 processors activated (8.00 BogoMIPS).
[    0.010608] CPU: All CPU(s) started in SVC mode.
[    0.011595] devtmpfs: initialized
[    0.020125] VFP support v0.3: implementor 41 architecture 2 part 30 variant 5 rev 1
[    0.021092] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.021123] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[    0.025439] xor: measuring software checksum speed
[    0.064336]    arm4regs  :   666.000 MB/sec
[    0.104337]    8regs     :   633.000 MB/sec
[    0.144344]    32regs    :   586.000 MB/sec
[    0.184343]    neon      :   657.000 MB/sec
[    0.184356] xor: using function: arm4regs (666.000 MB/sec)
[    0.184435] pinctrl core: initialized pinctrl subsystem
[    0.185471] thermal_sys: Registered thermal governor 'fair_share'
[    0.185477] thermal_sys: Registered thermal governor 'bang_bang'
[    0.185491] thermal_sys: Registered thermal governor 'step_wise'
[    0.185501] thermal_sys: Registered thermal governor 'user_space'
[    0.186789] NET: Registered protocol family 16
[    0.189976] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.190729] audit: initializing netlink subsys (disabled)
[    0.191046] audit: type=2000 audit(0.188:1): state=initialized audit_enabled=0 res=1
[    0.192079] cpuidle: using governor menu
[    0.192367] No ATAGs?
[    0.192566] hw-breakpoint: found 2 (+1 reserved) breakpoint and 1 watchpoint registers.
[    0.192583] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.194443] clk-m8b-test c1104000.system-controller:clock-controller: m8b_clkc_test INIT
....
Bernard Zhao April 30, 2020, 3:33 a.m. UTC | #3
From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Date: 2020-04-30 01:43:55
To:  Jerome Brunet <jbrunet@baylibre.com>
Cc:  Bernard Zhao <bernard@vivo.com>,Neil Armstrong <narmstrong@baylibre.com>,Stephen Boyd <sboyd@kernel.org>,Kevin Hilman <khilman@baylibre.com>,linux-amlogic@lists.infradead.org,linux-clk@vger.kernel.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
Subject: Re: [PATCH] clk/meson: fixes memleak issue in init err branch>Hi Jerome,
>
>On Wed, Apr 29, 2020 at 2:37 PM Jerome Brunet <jbrunet@baylibre.com> wrote:
>>
>>
>> On Wed 29 Apr 2020 at 05:14, Bernard Zhao <bernard@vivo.com> wrote:
>>
>> > In common init function, when run into err branch, we didn`t
>> > use kfree to release kzmalloc area, this may bring in memleak
>>
>> Thx for reporting this Bernard.
>> I'm not a fan of adding kfree everywhere. I'd much prefer a label and
>> clear error exit path.
>>
>> That being said, the allocation is probably not the only thing that
>> needs to be undone in case of error. I guess this is due to conversion
>> to CLK_OF_DECLARE_DRIVER() which forced to drop all the devm_
>> This was done because the clock controller was required early in the
>> boot sequence.
>>
>> There is 2 paths to properly solve this:
>> 1) Old school: manually undo everything with every error exit condition
>>    Doable but probably a bit messy
>> 2) Convert back the driver to a real platform driver and use devm_.
>>    We would still need the controller to register early but I wonder if
>>    we could use the same method as drivers/clk/mediatek/clk-mt2701.c and
>>    use arch_initcall() ?
>>
>> Martin, you did the initial conversion, what do you think of option 2 ?
>I tried it with the attached patch
>unfortunately my "m8b_clkc_test_probe" is still run too late
>
>> Would it still answer the problem you were trying to solve back then ?
>I'm afraid it does not:
>- the resets are needed early for SMP initialization
>- the clocks are needed even earlier for timer registration (we have
>both, the ARM TWD timer and some Amlogic custom timer. both have clock
>inputs)
>
>> One added benefit of option 2 is we could drop CLK_OF_DECLARE_DRIVER().
>> We could even do the same in for the other SoCs, which I suppose would
>> avoid a fair amount of probe deferral.
>it would be great, indeed
>but this will only work once timer initialization and SMP boot can
>happen at a later stage
>
>If the clock controller registration fails the board won't boot. Yes,
>cleaning up memory is good, but in this specific case it will add a
>couple of extra CPU cycles before the kernel is dead
>So, if we want to ignore that fact then I agree with your first option
>(undoing things the "old school" way).
>

Hi
I am not sure whether my understanding is correct. 
I feels that the failure of our module can not block the entire kernel from starting. 
Maybe we should throw an exception, clear the status, as "old way", 
and continue to execute the kernel.

And if our module requires that the kernel cannot continue to run when the exception occurs,
then we do not need to return in the error branch, also we do not need to kfree, just BUG_ON().

Regards,
Bernard

>Martin
Martin Blumenstingl May 2, 2020, 11:10 a.m. UTC | #4
Hi Bernhard,

On Thu, Apr 30, 2020 at 5:33 AM 赵军奎 <bernard@vivo.com> wrote:
[...]
> I am not sure whether my understanding is correct.
> I feels that the failure of our module can not block the entire kernel from starting.
> Maybe we should throw an exception, clear the status, as "old way",
> and continue to execute the kernel.
I added a HACK right at the beginning of meson8b_clkc_init_common where I added:
if (true)
  return; // HACK: simulate an error

when I then try to boot the resulting kernel there's silence after
u-boot is done:
Starting kernel ...
(output stops here)

This is expected, because the UART clock is provided by this clock
controller. And since we didn't register it there will be no serial
output.

Then I added "earlycon" to the boot args and attached the output to this mail.
The result is still not great, because only the early console is
working. Also timer initialization (smp_twd) as well as SMP startup
failed.
All other peripherals also failed to probe, because almost everything
on this SoC depends on this main clock controller (the two exceptions
that I know are: the always-on remote processor and the DDR clock
controller).

I hope that this explains the behavior when the main clock and reset
controllers are not registered (either due to my hack or if there's an
actual error).
Please let me know if you have more questions.
Now I would like to hear your suggestion, how to handle errors in this driver!


Regards
Martin
Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x200
[    0.000000] Linux version 5.7.0-rc3-00262-g0f5b56dbfddb-dirty (xdarklight@blackbox) (gcc version 9.3.0 (Arch Repository), GNU ld (GNU Binutils) 2.34) #6443 SMP PREEMPT Sat May 2 12:53:32 CEST 2020
[    0.000000] CPU: ARMv7 Processor [410fc051] revision 1 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: Hardkernel ODROID-C1
[    0.000000] earlycon: meson0 at MMIO 0xc81004c0 (options '115200n8')
[    0.000000] printk: bootconsole [meson0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 64 MiB at 0x3c000000
[    0.000000] percpu: Embedded 16 pages/cpu s34824 r8192 d22520 u65536
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 259908
[    0.000000] Kernel command line: console=ttyAML0,115200 earlycon
[    0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, linear)
[    0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 926352K/1046528K available (18432K kernel code, 711K rwdata, 6772K rodata, 1024K init, 958K bss, 54640K reserved, 65536K cma-reserved, 196608K highmem)
[    0.000000] random: get_random_u32 called from __kmem_cache_create+0x28/0x38c with crng_init=0
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
[    0.000000]  Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000000] irq_meson_gpio: 119 to 8 gpio interrupt mux initialized
[    0.000000] L2C: DT/platform modifies aux control register: 0x02060000 -> 0x02460000
[    0.000000] L2C-310 erratum 769419 enabled
[    0.000000] L2C-310 ID prefetch enabled, offset 1 lines
[    0.000000] L2C-310 dynamic clock gating enabled, standby mode enabled
[    0.000000] L2C-310 cache controller enabled, 8 ways, 512 kB
[    0.000000] L2C-310: CACHE_ID 0x4100a0c9, AUX_CTRL 0x36460000
[    0.000015] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
[    0.007539] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.016825] Switching to timer-based delay loop, resolution 1000ns
[    0.023071] smp_twd: clock not found -517
[    0.027362] Console: colour dummy device 80x30
[    0.031377] Calibrating local timer... 299.95MHz.
[    0.052876] Calibrating delay loop (skipped), value calculated using timer frequency.. 2.00 BogoMIPS (lpj=4000)
[    0.061955] pid_max: default: 32768 minimum: 301
[    0.066786] LSM: Security Framework initializing
[    0.071352] Smack:  Initializing.
[    0.074420] Smack:  IPv6 port labeling enabled.
[    0.079072] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[    0.086206] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[    0.094892] CPU: Testing write buffer coherency: ok
[    0.099026] CPU0: thread -1, cpu 0, socket 2, mpidr 80000200
[    0.105359] Setting up static identity map for 0x300000 - 0x300060
[    0.110723] rcu: Hierarchical SRCU implementation.
[    0.116113] smp: Bringing up secondary CPUs ...
[    0.120503] Couldn't get the reset controller for CPU1
[    0.124961] CPU1: failed to boot: -517
[    0.129397] Couldn't get the reset controller for CPU2
[    0.133794] CPU2: failed to boot: -517
[    0.138172] Couldn't get the reset controller for CPU3
[    0.142624] CPU3: failed to boot: -517
[    0.146396] smp: Brought up 1 node, 1 CPU
[    0.150313] SMP: Total of 1 processors activated (2.00 BogoMIPS).
[    0.156364] CPU: All CPU(s) started in SVC mode.
[    0.161525] devtmpfs: initialized
[    0.169715] VFP support v0.3: implementor 41 architecture 2 part 30 variant 5 rev 1
[    0.172541] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.181587] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[    0.191529] xor: measuring software checksum speed
[    0.232849]    arm4regs  :  1011.000 MB/sec
[    0.272840]    8regs     :   960.000 MB/sec
[    0.312832]    32regs    :   889.000 MB/sec
[    0.352826]    neon      :   996.000 MB/sec
[    0.352849] xor: using function: arm4regs (1011.000 MB/sec)
[    0.356979] pinctrl core: initialized pinctrl subsystem
[    0.362847] thermal_sys: Registered thermal governor 'fair_share'
[    0.362852] thermal_sys: Registered thermal governor 'bang_bang'
[    0.368204] thermal_sys: Registered thermal governor 'step_wise'
[    0.374159] thermal_sys: Registered thermal governor 'user_space'
[    0.381055] NET: Registered protocol family 16
[    0.392660] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.397957] audit: initializing netlink subsys (disabled)
[    0.403741] cpuidle: using governor menu
[    0.406873] No ATAGs?
[    0.406927] audit: type=2000 audit(0.344:1): state=initialized audit_enabled=0 res=1
[    0.416684] hw-breakpoint: found 2 (+1 reserved) breakpoint and 1 watchpoint registers.
[    0.424661] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.473138] cryptd: max_cpu_qlen set to 1000
[    0.502040] VCC1V8: supplied by P5V0
[    0.502423] VCC3V3: supplied by P5V0
[    0.503832] DDR_VDDC: supplied by P5V0
[    0.507998] VDD_RTC: supplied by VCC3V3
[    0.512724] SCSI subsystem initialized
[    0.515448] usbcore: registered new interface driver usbfs
[    0.520450] usbcore: registered new interface driver hub
[    0.525724] usbcore: registered new device driver usb
[    0.530974] pps_core: LinuxPPS API ver. 1 registered
[    0.535513] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    0.544609] PTP clock support registered
[    0.548870] EDAC MC: Ver: 3.0.0
[    0.552509] Advanced Linux Sound Architecture Driver Initialized.
[    0.558346] Bluetooth: Core ver 2.22
[    0.561277] NET: Registered protocol family 31
[    0.565638] Bluetooth: HCI device and connection manager initialized
[    0.571961] Bluetooth: HCI socket layer initialized
[    0.576808] Bluetooth: L2CAP socket layer initialized
[    0.581844] Bluetooth: SCO socket layer initialized
[    0.586717] NetLabel: Initializing
[    0.590054] NetLabel:  domain hash size = 128
[    0.594378] NetLabel:  protocols = UNLABELED CIPSOv4 CALIPSO
[    0.600076] NetLabel:  unlabeled traffic allowed by default
[    0.606210] clocksource: Switched to clocksource timer
[    0.611212] VFS: Disk quotas dquot_6.6.0
[    0.614643] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.621686] FS-Cache: Loaded
[    0.624548] CacheFiles: Loaded
[    0.637818] NET: Registered protocol family 2
[    0.638657] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[    0.644913] TCP established hash table entries: 8192 (order: 3, 32768 bytes, linear)
[    0.652650] TCP bind hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.659782] TCP: Hash tables configured (established 8192 bind 8192)
[    0.666181] UDP hash table entries: 512 (order: 2, 16384 bytes, linear)
[    0.672681] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes, linear)
[    0.679907] NET: Registered protocol family 1
[    0.684602] RPC: Registered named UNIX socket transport module.
[    0.689878] RPC: Registered udp transport module.
[    0.694492] RPC: Registered tcp transport module.
[    0.699162] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.706046] NET: Registered protocol family 44
[    0.710460] Trying to unpack rootfs image as initramfs...
[    0.805050] Freeing initrd memory: 14928K
[    0.805900] hw perfevents: enabled with armv7_cortex_a5 PMU driver, 3 counters available
[    0.924392] Initialise system trusted keyrings
[    0.924673] workingset: timestamp_bits=14 max_order=18 bucket_order=4
[    0.935101] zbud: loaded
[    0.936320] DLM installed
[    0.937283] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.942339] NFS: Registering the id_resolver key type
[    0.945568] Key type id_resolver registered
[    0.949758] Key type id_legacy registered
[    0.953714] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.960376] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.968434] FS-Cache: Netfs 'cifs' registered for caching
[    0.972703] Key type cifs.spnego registered
[    0.976269] Key type cifs.idmap registered
[    0.980387] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[    0.986863] fuse: init (API version 7.31)
[    0.991292] NILFS version 2 loaded
[    1.032645] NET: Registered protocol family 38
[    1.032686] async_tx: api initialized (async)
[    1.035887] Key type asymmetric registered
[    1.039922] Asymmetric key parser 'x509' registered
[    1.044876] bounce: pool size: 64 pages
[    1.048633] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 245)
[    1.056192] io scheduler mq-deadline registered
[    1.060435] io scheduler kyber registered
[    1.064570] io scheduler bfq registered
[    1.071239] GPIO line 417 (usb-hub-reset) hogged as output/high
[    1.078704] soc soc0: Amlogic Meson8b (S805) RevA (1b - 0:B72) detected
[    1.081259] pwm-regulator: supplied by regulator-dummy
[    1.086189] pwm-regulator: supplied by regulator-dummy
[    1.091841] Serial: 8250/16550 driver, 6 ports, IRQ sharing enabled
[    1.101248] usbcore: registered new interface driver udl
[    1.125262] brd: module loaded
[    1.137387] loop: module loaded
[    1.194698] drbd: initialized. Version: 8.4.11 (api:1/proto:86-101)
[    1.195329] drbd: built-in
[    1.198012] drbd: registered as block device major 147
[    1.203698] rbd: loaded (major 253)
[    1.207340] zram: Added device: zram0
[    1.212312] null_blk: module loaded
[    1.213687] dummy-irq: no IRQ given.  Use irq=N
[    1.219162] Loading iSCSI transport class v2.0-870.
[    1.223710] rdac: device handler registered
[    1.227422] hp_sw: device handler registered
[    1.231485] emc: device handler registered
[    1.235739] alua: device handler registered
[    1.240147] iscsi: registered transport (tcp)
[    1.245280] Rounding down aligned max_sectors from 4294967295 to 4294967288
[    1.251235] db_root: cannot open: /etc/target
[    1.255930] SSFDC read-only Flash Translation layer
[    1.260208] mtdoops: mtd device (mtddev=name/number) must be supplied
[    1.269821] eql: Equalizer2002: Simon Janes (simon@ncm.com) and David S. Miller (davem@redhat.com)
[    1.276707] MACsec IEEE 802.1AE
[    1.280106] libphy: Fixed MDIO Bus: probed
[    1.283027] tun: Universal TUN/TAP device driver, 1.6
[    1.287940] ipddp.c:v0.01 8/28/97 Bradford W. Johnson <johns393@maroon.tc.umn.edu>
[    1.295683] ipddp0: Appletalk-IP Encap. mode by Bradford W. Johnson <johns393@maroon.tc.umn.edu>
[    1.306738] usbcore: registered new interface driver ath9k_htc
[    1.311349] aoe: AoE v85 initialised.
[    1.314417] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    1.319903] ehci-platform: EHCI generic platform driver
[    1.325370] usbcore: registered new interface driver cdc_acm
[    1.330695] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    1.338705] usbcore: registered new interface driver usblp
[    1.344149] usbcore: registered new interface driver cdc_wdm
[    1.349785] usbcore: registered new interface driver usbtmc
[    1.355560] usbcore: registered new interface driver uas
[    1.360658] usbcore: registered new interface driver usb-storage
[    1.366575] usbcore: registered new interface driver ums-alauda
[    1.372458] usbcore: registered new interface driver ums-cypress
[    1.378440] usbcore: registered new interface driver ums-datafab
[    1.384406] usbcore: registered new interface driver ums_eneub6250
[    1.390554] usbcore: registered new interface driver ums-freecom
[    1.396527] usbcore: registered new interface driver ums-isd200
[    1.402424] usbcore: registered new interface driver ums-jumpshot
[    1.408480] usbcore: registered new interface driver ums-karma
[    1.414280] usbcore: registered new interface driver ums-onetouch
[    1.420353] usbcore: registered new interface driver ums-realtek
[    1.426317] usbcore: registered new interface driver ums-sddr09
[    1.432204] usbcore: registered new interface driver ums-sddr55
[    1.438090] usbcore: registered new interface driver ums-usbat
[    1.443905] udc-core: couldn't find an available UDC - added [g_ether] to list of pending drivers
[    1.453057] mousedev: PS/2 mouse device common for all mice
[    1.459427] usbcore: registered new interface driver appletouch
[    1.464222] usbcore: registered new interface driver bcm5974
[    1.470239] usbcore: registered new interface driver synaptics_usb
[    1.476114] usbcore: registered new interface driver ati_remote2
[    1.481924] cm109: Keymap for Komunikate KIP1000 phone loaded
[    1.487648] usbcore: registered new interface driver cm109
[    1.493039] cm109: CM109 phone driver: 20080805 (C) Alfred E. Heggestad
[    1.500093] usbcore: registered new interface driver ims_pcu
[    1.505314] usbcore: registered new interface driver keyspan_remote
[    1.511721] usbcore: registered new interface driver powermate
[    1.518367] usbcore: registered new interface driver yealink
[    1.523484] i2c /dev entries driver
[    1.527042] IR NEC protocol handler initialized
[    1.530883] IR RC5(x/sz) protocol handler initialized
[    1.535896] IR RC6 protocol handler initialized
[    1.540398] IR JVC protocol handler initialized
[    1.544900] IR Sony protocol handler initialized
[    1.549489] IR SANYO protocol handler initialized
[    1.554165] IR Sharp protocol handler initialized
[    1.558842] IR MCE Keyboard/mouse protocol handler initialized
[    1.564642] IR XMP protocol handler initialized
[    1.569145] ir_imon_decoder: IR iMON protocol handler initialized
[    1.575207] IR RCMM protocol handler initialized
[    1.579858] usbcore: registered new interface driver ati_remote
[    1.585873] usbcore: registered new interface driver imon
[    1.591117] usbcore: registered new interface driver imon_raw
[    1.596817] usbcore: registered new interface driver mceusb
[    1.602588] Registered IR keymap rc-empty
[    1.606400] rc rc0: meson-ir as /devices/platform/soc/c8100000.aobus/c8100480.ir-receiver/rc/rc0
[    1.615222] rc rc0: lirc_dev: driver meson-ir registered at minor = 0, raw IR receiver, no transmitter
[    1.624461] input: meson-ir as /devices/platform/soc/c8100000.aobus/c8100480.ir-receiver/rc/rc0/input0
[    1.633936] meson-ir c8100480.ir-receiver: receiver initialized
[    1.639728] usbcore: registered new interface driver redrat3
[    1.645186] usbcore: registered new interface driver streamzap
[    1.650913] Registered IR keymap rc-empty
[    1.654948] rc rc1: rc-core loopback device as /devices/virtual/rc/rc1
[    1.661541] rc rc1: lirc_dev: driver rc-loopback registered at minor = 1, raw IR receiver, raw IR transmitter
[    1.671387] input: rc-core loopback device as /devices/virtual/rc/rc1/input1
[    1.678963] usbcore: registered new interface driver igorplugusb
[    1.684310] usbcore: registered new interface driver iguanair
[    1.689986] usbcore: registered new interface driver ttusbir
[    1.696234] meson-ao-cec c8100100.cec: core clock request failed
[    1.701653] meson-ao-cec c8100100.cec: CEC controller registration failed
[    1.708440] meson-ao-cec: probe of c8100100.cec failed with error -2
[    1.714745] pps_ldisc: PPS line discipline registered
[    1.721530] usbcore: registered new interface driver pcwd_usb
[    1.726434] meson_wdt c1109900.watchdog: Watchdog enabled (timeout=8 sec, nowayout=1)
[    1.733693] softdog: initialized. soft_noboot=0 soft_margin=60 sec soft_panic=0 (nowayout=1)
[    1.741675] md-cluster: support raid1 and raid10 (limited support)
[    1.747695] Registering Cluster MD functions
[    1.752663] device-mapper: uevent: version 1.0.3
[    1.756925] device-mapper: ioctl: 4.42.0-ioctl (2020-02-27) initialised: dm-devel@redhat.com
[    1.765654] device-mapper: multipath round-robin: version 1.2.0 loaded
[    1.771481] device-mapper: multipath queue-length: version 0.2.0 loaded
[    1.778032] device-mapper: multipath service-time: version 0.3.0 loaded
[    1.784632] device-mapper: dm-log-userspace: version 1.3.0 loaded
[    1.790711] Bluetooth: HCI UART driver ver 2.3
[    1.795064] Bluetooth: HCI UART protocol H4 registered
[    1.800165] Bluetooth: HCI UART protocol BCSP registered
[    1.805480] Bluetooth: HCI UART protocol LL registered
[    1.810559] Bluetooth: HCI UART protocol ATH3K registered
[    1.815950] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    1.822278] Bluetooth: HCI UART protocol Intel registered
[    1.827615] Bluetooth: HCI UART protocol Broadcom registered
[    1.833184] Bluetooth: HCI UART protocol QCA registered
[    1.842152] ledtrig-cpu: registered to indicate activity on CPUs
[    1.844522] hid: raw HID events driver (C) Jiri Kosina
[    1.854935] usbcore: registered new interface driver usbhid
[    1.854966] usbhid: USB HID core driver
[    1.859433] meson-saradc c1108680.adc: failed to get core clk
[    1.865953] meson-mx-efuse da000000.nvmem: Failed to get core clock
[    1.873713] oprofile: using timer interrupt.
[    1.875194] pktgen: Packet Generator for packet performance testing. Version: 2.75
[    1.882885] NET: Registered protocol family 26
[    1.886972] GACT probability on
[    1.890034] Mirror/redirect action on
[    1.893709] Simple TC action Loaded
[    1.897664] netem: version 1.3
[    1.900244] u32 classifier
[    1.902862]     Performance counters on
[    1.906703]     input device check on
[    1.910369]     Actions configured
[    1.929660] xt_time: kernel timezone is -0000
[    1.929719] IPVS: Registered protocols ()
[    1.932628] IPVS: Connection hash table configured (size=4096, memory=32Kbytes)
[    1.940441] IPVS: ipvs loaded.
[    1.942917] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    1.948719] gre: GRE over IPv4 demultiplexor driver
[    1.953050] ip_gre: GRE over IPv4 tunneling driver
[    1.959049] IPv4 over IPsec tunneling driver
[    1.963157] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    1.968518] Initializing XFRM netlink socket
[    1.972636] IPsec XFRM device driver
[    1.976735] NET: Registered protocol family 10
[    2.013610] Segment Routing with IPv6
[    2.013792] mip6: Mobile IPv6
[    2.016109] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    2.021831] ip6_gre: GRE over IPv6 tunneling driver
[    2.026083] NET: Registered protocol family 17
[    2.029861] NET: Registered protocol family 15
[    2.034350] Bridge firewalling registered
[    2.038406] NET: Registered protocol family 5
[    2.042723] NET: Unregistered protocol family 5
[    2.047214] Bluetooth: RFCOMM TTY layer initialized
[    2.051950] Bluetooth: RFCOMM socket layer initialized
[    2.056985] Bluetooth: RFCOMM ver 1.11
[    2.060723] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    2.065990] Bluetooth: BNEP filters: protocol multicast
[    2.071189] Bluetooth: BNEP socket layer initialized
[    2.076133] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[    2.081981] Bluetooth: HIDP socket layer initialized
[    2.087127] 8021q: 802.1Q VLAN Support v1.8
[    2.096526] DCCP: Activated CCID 2 (TCP-like)
[    2.096585] DCCP: Activated CCID 3 (TCP-Friendly Rate Control)
[    2.101812] sctp: Hash tables configured (bind 512/512)
[    2.107072] NET: Registered protocol family 21
[    2.111066] Registered RDS/tcp transport
[    2.114779] Key type dns_resolver registered
[    2.119025] Key type ceph registered
[    2.122892] libceph: loaded (mon/osd proto 15/24)
[    2.127301] openvswitch: Open vSwitch switching datapath
[    2.133262] NET: Registered protocol family 40
[    2.137016] mpls_gso: MPLS GSO support
[    2.141128] ThumbEE CPU extension supported.
[    2.144927] Registering SWP/SWPB emulation handler
[    2.196658] registered taskstats version 1
[    2.196691] Loading compiled-in X.509 certificates
[    2.201087] zswap: loaded using pool zstd/zbud
[    2.205217] Key type ._fscrypt registered
[    2.208404] Key type .fscrypt registered
[    2.212236] Key type fscrypt-provisioning registered
[    2.219838] TFLASH_VDD: supplied by VCC3V3
[    2.240281] meson-saradc c1108680.adc: failed to get core clk
[    2.240883] meson-mx-efuse da000000.nvmem: Failed to get core clock
[    2.264172] meson-saradc c1108680.adc: failed to get core clk
[    2.264768] meson-mx-efuse da000000.nvmem: Failed to get core clock
[    2.272157] printk: console [netcon0] enabled
[    2.275015] netconsole: network logging started
[    2.279576] gtp: GTP module loaded (pdp ctx size 64 bytes)
[    2.285248] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[    2.310017] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[    2.311254] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[    2.319607] ALSA device list:
[    2.322492]   No soundcards found.
[    2.325845] Warning: unable to open an initial console.
[    2.331074] cfg80211: failed to load regulatory.db
[    2.337329] Freeing unused kernel memory: 1024K
[    2.346449] Run /init as init process
[    2.407250] random: systemd-tmpfile: uninitialized urandom read (16 bytes read)
[    2.420304] systemd-udevd[380]: starting version 232
[    2.424238] random: systemd-udevd: uninitialized urandom read (16 bytes read)
[    2.430813] random: systemd-udevd: uninitialized urandom read (16 bytes read)
[    4.182558] : Can't open blockdev
[    4.182693] : Can't open blockdev
[    4.184018] fuseblk: Bad value for 'source'
[    4.257421] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100
[    4.259445] CPU: 0 PID: 1 Comm: switch_root Not tainted 5.7.0-rc3-00262-g0f5b56dbfddb-dirty #6443
[    4.268269] Hardware name: Amlogic Meson platform
[    4.272972] [<c030f3f0>] (unwind_backtrace) from [<c030ad5c>] (show_stack+0x10/0x14)
[    4.280663] [<c030ad5c>] (show_stack) from [<c09330a4>] (dump_stack+0xb0/0xc4)
[    4.287848] [<c09330a4>] (dump_stack) from [<c03337b0>] (panic+0x11c/0x330)
[    4.294774] [<c03337b0>] (panic) from [<c0338740>] (do_exit+0xa9c/0xb10)
[    4.301440] [<c0338740>] (do_exit) from [<c033881c>] (do_group_exit+0x3c/0xb8)
[    4.308626] [<c033881c>] (do_group_exit) from [<c03388a8>] (__wake_up_parent+0x0/0x14)
[    4.316517] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100 ]---
diff mbox series

Patch

diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
index 34a70c4b4899..0f07d5a4cd16 100644
--- a/drivers/clk/meson/meson8b.c
+++ b/drivers/clk/meson/meson8b.c
@@ -3687,6 +3687,7 @@  static void __init meson8b_clkc_init_common(struct device_node *np,
 	if (ret) {
 		pr_err("%s: Failed to register clkc reset controller: %d\n",
 		       __func__, ret);
+		kfree(rstc);
 		return;
 	}
 
@@ -3710,8 +3711,10 @@  static void __init meson8b_clkc_init_common(struct device_node *np,
 			continue;
 
 		ret = of_clk_hw_register(np, clk_hw_onecell_data->hws[i]);
-		if (ret)
+		if (ret) {
+			kfree(rstc);
 			return;
+		}
 	}
 
 	meson8b_cpu_nb_data.cpu_clk = clk_hw_onecell_data->hws[CLKID_CPUCLK];
@@ -3727,13 +3730,16 @@  static void __init meson8b_clkc_init_common(struct device_node *np,
 	if (ret) {
 		pr_err("%s: failed to register the CPU clock notifier\n",
 		       __func__);
+		kfree(rstc);
 		return;
 	}
 
 	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get,
 				     clk_hw_onecell_data);
-	if (ret)
+	if (ret) {
 		pr_err("%s: failed to register clock provider\n", __func__);
+		kfree(rstc);
+	}
 }
 
 static void __init meson8_clkc_init(struct device_node *np)