Skip to content

Commit

Permalink
[PATCH] SRCU: report out-of-memory errors
Browse files Browse the repository at this point in the history
Currently the init_srcu_struct() routine has no way to report out-of-memory
errors.  This patch (as761) makes it return -ENOMEM when the per-cpu data
allocation fails.

The patch also makes srcu_init_notifier_head() report a BUG if a notifier
head can't be initialized.  Perhaps it should return -ENOMEM instead, but
in the most likely cases where this might occur I don't think any recovery
is possible.  Notifier chains generally are not created dynamically.

[[email protected]: avoid statement-with-side-effect in macro]
Signed-off-by: Alan Stern <[email protected]>
Acked-by: Paul E. McKenney <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
AlanStern authored and Linus Torvalds committed Oct 4, 2006
1 parent eabc069 commit e6a9201
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/linux/srcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct srcu_struct {
#define srcu_barrier()
#endif /* #else #ifndef CONFIG_PREEMPT */

void init_srcu_struct(struct srcu_struct *sp);
int init_srcu_struct(struct srcu_struct *sp);
void cleanup_srcu_struct(struct srcu_struct *sp);
int srcu_read_lock(struct srcu_struct *sp) __acquires(sp);
void srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp);
Expand Down
5 changes: 3 additions & 2 deletions kernel/srcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@
* to any other function. Each srcu_struct represents a separate domain
* of SRCU protection.
*/
void init_srcu_struct(struct srcu_struct *sp)
int init_srcu_struct(struct srcu_struct *sp)
{
sp->completed = 0;
sp->per_cpu_ref = alloc_percpu(struct srcu_struct_array);
mutex_init(&sp->mutex);
sp->per_cpu_ref = alloc_percpu(struct srcu_struct_array);
return (sp->per_cpu_ref ? 0 : -ENOMEM);
}

/*
Expand Down
3 changes: 2 additions & 1 deletion kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ EXPORT_SYMBOL_GPL(srcu_notifier_call_chain);
void srcu_init_notifier_head(struct srcu_notifier_head *nh)
{
mutex_init(&nh->mutex);
init_srcu_struct(&nh->srcu);
if (init_srcu_struct(&nh->srcu) < 0)
BUG();
nh->head = NULL;
}

Expand Down

0 comments on commit e6a9201

Please sign in to comment.