Compare
7cbaa0f4579f48e92639c6abb761fdef8fbade47..aaabefc79b0ff0018e8e3832169bbe359d0551fc
i2c: viai2c-wmt: Fix clock leak in wmt_i2c_probe()
In wmt_i2c_probe(), i2c->clk is acquired using of_clk_get(). If any
subsequent operation fails or when the module is unloaded, the clock
reference count is never decremented via clk_put(), leading to a
resource leak.
Switch to devm_clk_get() so that the clock is automatically managed
and released.
Fixes: 560746eb79d3 ("i2c: vt8500: Add support for I2C bus on Wondermedia SoCs")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://patch.msgid.link/20260916070631.1965713-1-vulab@iscas.ac.cn
Wentao Liang <vulab@iscas.ac.cn> · 2026-09-16 07:06 UTC · committed by Andi Shyti
5 files changed,
+34
−63
- drivers/i2c/busses/i2c-viai2c-wmt.c
- include/linux/futex.h
- include/linux/futex_types.h
- include/linux/irq-entry-common.h
- kernel/futex/core.c
modified drivers/i2c/busses/i2c-viai2c-wmt.c
| @@ -116,7 +116,7 @@ static int wmt_i2c_probe(struct platform_device *pdev) | |||
| 116 | 116 | if (err) | |
| 117 | 117 | return err; | |
| 118 | 118 | ||
| 119 | - | i2c->clk = of_clk_get(np, 0); | |
| 119 | + | i2c->clk = devm_clk_get(&pdev->dev, NULL); | |
| 120 | 120 | if (IS_ERR(i2c->clk)) | |
| 121 | 121 | return dev_err_probe(&pdev->dev, PTR_ERR(i2c->clk), | |
| 122 | 122 | "unable to request clock\n"); | |
modified include/linux/futex.h
| @@ -23,32 +23,28 @@ struct task_struct; | |||
| 23 | 23 | * 01 : Shared futex (PTHREAD_PROCESS_SHARED) | |
| 24 | 24 | * mapped on a file (reference on the underlying inode) | |
| 25 | 25 | * 10 : Shared futex (PTHREAD_PROCESS_SHARED) | |
| 26 | - | * (but private mapping on an mm) | |
| 26 | + | * (but private mapping on an mm, and reference taken on it) | |
| 27 | 27 | */ | |
| 28 | 28 | ||
| 29 | - | #define FUT_OFF_INODE 1 /* We set bit 0 if shared key identifies an inode */ | |
| 30 | - | #define FUT_OFF_MMSHARED 2 /* We set bit 1 if shared key identifies an mm */ | |
| 29 | + | #define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */ | |
| 30 | + | #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */ | |
| 31 | 31 | ||
| 32 | 32 | union futex_key { | |
| 33 | - | /* For FUT_OFF_INODE */ | |
| 34 | 33 | struct { | |
| 35 | 34 | u64 i_seq; | |
| 36 | 35 | unsigned long pgoff; | |
| 37 | 36 | unsigned int offset; | |
| 38 | 37 | /* unsigned int node; */ | |
| 39 | 38 | } shared; | |
| 40 | - | ||
| 41 | - | /* For FUT_OFF_MMSHARED or private */ | |
| 42 | 39 | struct { | |
| 43 | 40 | union { | |
| 44 | - | struct mm_struct *mm; /* for private */ | |
| 45 | - | u64 mm_seq; /* for FUT_OFF_MMSHARED */ | |
| 41 | + | struct mm_struct *mm; | |
| 42 | + | u64 __tmp; | |
| 46 | 43 | }; | |
| 47 | 44 | unsigned long address; | |
| 48 | 45 | unsigned int offset; | |
| 49 | 46 | /* unsigned int node; */ | |
| 50 | 47 | } private; | |
| 51 | - | ||
| 52 | 48 | struct { | |
| 53 | 49 | u64 ptr; | |
| 54 | 50 | unsigned long word; | |
| @@ -156,10 +152,11 @@ static inline void futex_set_vdso_cs_range(struct futex_mm_data *fd, unsigned in | |||
| 156 | 152 | static inline void futex_fixup_robust_unlock(struct pt_regs *regs) { } | |
| 157 | 153 | #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ | |
| 158 | 154 | ||
| 159 | - | #ifdef CONFIG_FUTEX | |
| 155 | + | ||
| 156 | + | #if defined(CONFIG_FUTEX_PRIVATE_HASH) || defined(CONFIG_FUTEX_ROBUST_UNLOCK) | |
| 160 | 157 | void futex_mm_init(struct mm_struct *mm); | |
| 161 | 158 | #else | |
| 162 | 159 | static inline void futex_mm_init(struct mm_struct *mm) { } | |
| 163 | - | #endif /* !CONFIG_FUTEX */ | |
| 160 | + | #endif | |
| 164 | 161 | ||
| 165 | 162 | #endif /* _LINUX_FUTEX_H */ | |
modified include/linux/futex_types.h
| @@ -85,12 +85,10 @@ struct futex_unlock_cs_ranges { }; | |||
| 85 | 85 | * struct futex_mm_data - Futex related per MM data | |
| 86 | 86 | * @phash: Futex private hash related data | |
| 87 | 87 | * @unlock: Futex unlock VDSO critical sections | |
| 88 | - | * @unique_id: Unique ID of the MM, for FUT_OFF_MMSHARED futexes | |
| 89 | 88 | */ | |
| 90 | 89 | struct futex_mm_data { | |
| 91 | 90 | struct futex_mm_phash phash; | |
| 92 | 91 | struct futex_unlock_cs_ranges unlock; | |
| 93 | - | atomic64_t unique_id; | |
| 94 | 92 | }; | |
| 95 | 93 | #else /* CONFIG_FUTEX */ | |
| 96 | 94 | struct futex_sched_data { }; | |
modified include/linux/irq-entry-common.h
| @@ -468,25 +468,6 @@ static inline void irqentry_exit_to_kernel_mode_preempt(struct pt_regs *regs, | |||
| 468 | 468 | irqentry_exit_cond_resched(); | |
| 469 | 469 | } | |
| 470 | 470 | ||
| 471 | - | /* | |
| 472 | - | * The deferred hrtimer rearm is the tail of the timer interrupt, moved to the | |
| 473 | - | * interrupt return path so that it runs after a possible reschedule. By now | |
| 474 | - | * irq_exit_rcu() has left lockdep's hardirq context. Re-enter it for the | |
| 475 | - | * rearm, so that the hrtimer base lock and the timekeeping sequence count are | |
| 476 | - | * not chained onto the locks held by the interrupted context, which would add | |
| 477 | - | * new lock chains for every lock stack an interrupt hits. | |
| 478 | - | * | |
| 479 | - | * The rearm on return to user mode needs no such annotation: no locks are | |
| 480 | - | * held there, so it uses the same lock chains as the rearm in hardirq | |
| 481 | - | * context. | |
| 482 | - | */ | |
| 483 | - | static __always_inline void irqentry_hrtimer_rearm_deferred(void) | |
| 484 | - | { | |
| 485 | - | lockdep_hardirq_enter(); | |
| 486 | - | hrtimer_rearm_deferred(); | |
| 487 | - | lockdep_hardirq_exit(); | |
| 488 | - | } | |
| 489 | - | ||
| 490 | 471 | /** | |
| 491 | 472 | * irqentry_exit_to_kernel_mode_after_preempt - Establish trace, lockdep and RCU state | |
| 492 | 473 | * @regs: Pointer to current's pt_regs | |
| @@ -510,7 +491,7 @@ irqentry_exit_to_kernel_mode_after_preempt(struct pt_regs *regs, irqentry_state_ | |||
| 510 | 491 | */ | |
| 511 | 492 | if (state.exit_rcu) { | |
| 512 | 493 | instrumentation_begin(); | |
| 513 | - | irqentry_hrtimer_rearm_deferred(); | |
| 494 | + | hrtimer_rearm_deferred(); | |
| 514 | 495 | /* Tell the tracer that IRET will enable interrupts */ | |
| 515 | 496 | trace_hardirqs_on_prepare(); | |
| 516 | 497 | lockdep_hardirqs_on_prepare(); | |
| @@ -521,7 +502,7 @@ irqentry_exit_to_kernel_mode_after_preempt(struct pt_regs *regs, irqentry_state_ | |||
| 521 | 502 | } | |
| 522 | 503 | ||
| 523 | 504 | instrumentation_begin(); | |
| 524 | - | irqentry_hrtimer_rearm_deferred(); | |
| 505 | + | hrtimer_rearm_deferred(); | |
| 525 | 506 | /* Covers both tracing and lockdep */ | |
| 526 | 507 | trace_hardirqs_on(); | |
| 527 | 508 | instrumentation_end(); | |
modified kernel/futex/core.c
| @@ -439,51 +439,45 @@ struct hrtimer_sleeper *futex_setup_timer(ktime_t *time, struct hrtimer_sleeper | |||
| 439 | 439 | } | |
| 440 | 440 | ||
| 441 | 441 | /* | |
| 442 | - | * Generate a machine wide unique identifier for this object (inode or mm). | |
| 442 | + | * Generate a machine wide unique identifier for this inode. | |
| 443 | 443 | * | |
| 444 | 444 | * This relies on u64 not wrapping in the life-time of the machine; which with | |
| 445 | 445 | * 1ns resolution means almost 585 years. | |
| 446 | + | * | |
| 447 | + | * This further relies on the fact that a well formed program will not unmap | |
| 448 | + | * the file while it has a (shared) futex waiting on it. This mapping will have | |
| 449 | + | * a file reference which pins the mount and inode. | |
| 450 | + | * | |
| 451 | + | * If for some reason an inode gets evicted and read back in again, it will get | |
| 452 | + | * a new sequence number and will _NOT_ match, even though it is the exact same | |
| 453 | + | * file. | |
| 454 | + | * | |
| 455 | + | * It is important that futex_match() will never have a false-positive, esp. | |
| 456 | + | * for PI futexes that can mess up the state. The above argues that false-negatives | |
| 457 | + | * are only possible for malformed programs. | |
| 446 | 458 | */ | |
| 447 | - | static u64 get_object_id(atomic64_t *object_seq) | |
| 459 | + | static u64 get_inode_sequence_number(struct inode *inode) | |
| 448 | 460 | { | |
| 449 | - | static atomic64_t last_assigned_seq; | |
| 461 | + | static atomic64_t i_seq; | |
| 450 | 462 | u64 old; | |
| 451 | 463 | ||
| 452 | - | /* Does the object already have a sequence number? */ | |
| 453 | - | old = atomic64_read(object_seq); | |
| 464 | + | /* Does the inode already have a sequence number? */ | |
| 465 | + | old = atomic64_read(&inode->i_sequence); | |
| 454 | 466 | if (likely(old)) | |
| 455 | 467 | return old; | |
| 456 | 468 | ||
| 457 | 469 | for (;;) { | |
| 458 | - | u64 new = atomic64_inc_return(&last_assigned_seq); | |
| 470 | + | u64 new = atomic64_inc_return(&i_seq); | |
| 459 | 471 | if (WARN_ON_ONCE(!new)) | |
| 460 | 472 | continue; | |
| 461 | 473 | ||
| 462 | 474 | old = 0; | |
| 463 | - | if (!atomic64_try_cmpxchg_relaxed(object_seq, &old, new)) | |
| 475 | + | if (!atomic64_try_cmpxchg_relaxed(&inode->i_sequence, &old, new)) | |
| 464 | 476 | return old; | |
| 465 | 477 | return new; | |
| 466 | 478 | } | |
| 467 | 479 | } | |
| 468 | 480 | ||
| 469 | - | /* | |
| 470 | - | * This relies on the fact that a well formed program will not unmap | |
| 471 | - | * the file while it has a (shared) futex waiting on it. This mapping will have | |
| 472 | - | * a file reference which pins the mount and inode. | |
| 473 | - | * | |
| 474 | - | * If for some reason an inode gets evicted and read back in again, it will get | |
| 475 | - | * a new sequence number and will _NOT_ match, even though it is the exact same | |
| 476 | - | * file. | |
| 477 | - | * | |
| 478 | - | * It is important that futex_match() will never have a false-positive, esp. | |
| 479 | - | * for PI futexes that can mess up the state. The above argues that false-negatives | |
| 480 | - | * are only possible for malformed programs. | |
| 481 | - | */ | |
| 482 | - | static u64 get_inode_sequence_number(struct inode *inode) | |
| 483 | - | { | |
| 484 | - | return get_object_id(&inode->i_sequence); | |
| 485 | - | } | |
| 486 | - | ||
| 487 | 481 | /** | |
| 488 | 482 | * get_futex_key() - Get parameters which are the keys for a futex | |
| 489 | 483 | * @uaddr: virtual address of the futex | |
| @@ -689,8 +683,8 @@ again: | |||
| 689 | 683 | goto out; | |
| 690 | 684 | } | |
| 691 | 685 | ||
| 692 | - | key->both.offset |= FUT_OFF_MMSHARED; | |
| 693 | - | key->private.mm_seq = get_object_id(&mm->futex.unique_id); | |
| 686 | + | key->both.offset |= FUT_OFF_MMSHARED; /* ref taken on mm */ | |
| 687 | + | key->private.mm = mm; | |
| 694 | 688 | key->private.address = address; | |
| 695 | 689 | ||
| 696 | 690 | } else { | |
| @@ -2061,12 +2055,13 @@ static void futex_robust_unlock_init_mm(struct futex_mm_data *fd) | |||
| 2061 | 2055 | static inline void futex_robust_unlock_init_mm(struct futex_mm_data *fd) { } | |
| 2062 | 2056 | #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ | |
| 2063 | 2057 | ||
| 2058 | + | #if defined(CONFIG_FUTEX_PRIVATE_HASH) || defined(CONFIG_FUTEX_ROBUST_UNLOCK) | |
| 2064 | 2059 | void futex_mm_init(struct mm_struct *mm) | |
| 2065 | 2060 | { | |
| 2066 | - | atomic64_set(&mm->futex.unique_id, 0); | |
| 2067 | 2061 | futex_hash_init_mm(&mm->futex); | |
| 2068 | 2062 | futex_robust_unlock_init_mm(&mm->futex); | |
| 2069 | 2063 | } | |
| 2064 | + | #endif | |
| 2070 | 2065 | ||
| 2071 | 2066 | int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4) | |
| 2072 | 2067 | { | |