2019-06-01 08:08:51 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2008-02-21 23:13:36 +00:00
|
|
|
* attribute_container.h - a generic container for all classes
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ATTRIBUTE_CONTAINER_H_
|
|
|
|
#define _ATTRIBUTE_CONTAINER_H_
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2005-08-22 15:06:19 +00:00
|
|
|
#include <linux/klist.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-01-30 16:46:54 +00:00
|
|
|
struct device;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct attribute_container {
|
|
|
|
struct list_head node;
|
2005-08-22 15:06:19 +00:00
|
|
|
struct klist containers;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct class *class;
|
2009-06-24 17:06:31 +00:00
|
|
|
const struct attribute_group *grp;
|
2008-02-21 23:13:36 +00:00
|
|
|
struct device_attribute **attrs;
|
2005-04-16 22:20:36 +00:00
|
|
|
int (*match)(struct attribute_container *, struct device *);
|
|
|
|
#define ATTRIBUTE_CONTAINER_NO_CLASSDEVS 0x01
|
|
|
|
unsigned long flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
attribute_container_no_classdevs(struct attribute_container *atc)
|
|
|
|
{
|
|
|
|
return atc->flags & ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
attribute_container_set_no_classdevs(struct attribute_container *atc)
|
|
|
|
{
|
|
|
|
atc->flags |= ATTRIBUTE_CONTAINER_NO_CLASSDEVS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int attribute_container_register(struct attribute_container *cont);
|
2008-04-02 15:05:48 +00:00
|
|
|
int __must_check attribute_container_unregister(struct attribute_container *cont);
|
2005-04-16 22:20:36 +00:00
|
|
|
void attribute_container_create_device(struct device *dev,
|
|
|
|
int (*fn)(struct attribute_container *,
|
|
|
|
struct device *,
|
2008-02-21 23:13:36 +00:00
|
|
|
struct device *));
|
2005-04-16 22:20:36 +00:00
|
|
|
void attribute_container_add_device(struct device *dev,
|
|
|
|
int (*fn)(struct attribute_container *,
|
|
|
|
struct device *,
|
2008-02-21 23:13:36 +00:00
|
|
|
struct device *));
|
2005-04-16 22:20:36 +00:00
|
|
|
void attribute_container_remove_device(struct device *dev,
|
|
|
|
void (*fn)(struct attribute_container *,
|
|
|
|
struct device *,
|
2008-02-21 23:13:36 +00:00
|
|
|
struct device *));
|
2005-04-16 22:20:36 +00:00
|
|
|
void attribute_container_device_trigger(struct device *dev,
|
|
|
|
int (*fn)(struct attribute_container *,
|
|
|
|
struct device *,
|
2008-02-21 23:13:36 +00:00
|
|
|
struct device *));
|
scsi: drivers: base: Support atomic version of attribute_container_device_trigger
attribute_container_device_trigger invokes callbacks that may fail for one
or more classdevs, for instance, the transport_add_class_device callback,
called during transport creation, does memory allocation. This
information, though, is not propagated to upper layers, and any driver
using the attribute_container_device_trigger API will not know whether any,
some, or all callbacks succeeded.
This patch implements a safe version of this dispatcher, to either succeed
all the callbacks or revert to the original state.
Link: https://lore.kernel.org/r/20200106185817.640331-2-krisman@collabora.com
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2020-01-06 18:58:15 +00:00
|
|
|
int attribute_container_device_trigger_safe(struct device *dev,
|
|
|
|
int (*fn)(struct attribute_container *,
|
|
|
|
struct device *,
|
|
|
|
struct device *),
|
|
|
|
int (*undo)(struct attribute_container *,
|
|
|
|
struct device *,
|
|
|
|
struct device *));
|
2005-04-16 22:20:36 +00:00
|
|
|
void attribute_container_trigger(struct device *dev,
|
|
|
|
int (*fn)(struct attribute_container *,
|
|
|
|
struct device *));
|
2008-02-21 23:13:36 +00:00
|
|
|
int attribute_container_add_attrs(struct device *classdev);
|
|
|
|
int attribute_container_add_class_device(struct device *classdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
int attribute_container_add_class_device_adapter(struct attribute_container *cont,
|
|
|
|
struct device *dev,
|
2008-02-21 23:13:36 +00:00
|
|
|
struct device *classdev);
|
|
|
|
void attribute_container_remove_attrs(struct device *classdev);
|
|
|
|
void attribute_container_class_device_del(struct device *classdev);
|
|
|
|
struct attribute_container *attribute_container_classdev_to_container(struct device *);
|
|
|
|
struct device *attribute_container_find_class_device(struct attribute_container *, struct device *);
|
|
|
|
struct device_attribute **attribute_container_classdev_to_attrs(const struct device *classdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#endif
|