Skip to content

Commit 752849e

Browse files
mellanoxbmcdvhart
authored andcommitted
platform/mellanox: Group create/destroy with attribute functions
Move the mlxreg_hotplug_device_create and _destroy functions up with the related attribute functions. No functional changes. Signed-off-by: Vadim Pasternak <vadimp@mellanox.com> Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> [dvhart: refactored commit into smaller functional changes] Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
1 parent 3d838f5 commit 752849e

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

drivers/platform/mellanox/mlxreg-hotplug.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ struct mlxreg_hotplug_priv_data {
9898
u8 fan_cache;
9999
};
100100

101+
static int mlxreg_hotplug_device_create(struct device *dev,
102+
struct mlxreg_hotplug_device *item)
103+
{
104+
item->adapter = i2c_get_adapter(item->nr);
105+
if (!item->adapter) {
106+
dev_err(dev, "Failed to get adapter for bus %d\n",
107+
item->nr);
108+
return -EFAULT;
109+
}
110+
111+
item->client = i2c_new_device(item->adapter, &item->brdinfo);
112+
if (!item->client) {
113+
dev_err(dev, "Failed to create client %s at bus %d at addr 0x%02x\n",
114+
item->brdinfo.type, item->nr, item->brdinfo.addr);
115+
i2c_put_adapter(item->adapter);
116+
item->adapter = NULL;
117+
return -EFAULT;
118+
}
119+
120+
return 0;
121+
}
122+
123+
static void mlxreg_hotplug_device_destroy(struct mlxreg_hotplug_device *item)
124+
{
125+
if (item->client) {
126+
i2c_unregister_device(item->client);
127+
item->client = NULL;
128+
}
129+
130+
if (item->adapter) {
131+
i2c_put_adapter(item->adapter);
132+
item->adapter = NULL;
133+
}
134+
}
135+
101136
static ssize_t mlxreg_hotplug_attr_show(struct device *dev,
102137
struct device_attribute *attr,
103138
char *buf)
@@ -183,41 +218,6 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
183218
return 0;
184219
}
185220

186-
static int mlxreg_hotplug_device_create(struct device *dev,
187-
struct mlxreg_hotplug_device *item)
188-
{
189-
item->adapter = i2c_get_adapter(item->nr);
190-
if (!item->adapter) {
191-
dev_err(dev, "Failed to get adapter for bus %d\n",
192-
item->nr);
193-
return -EFAULT;
194-
}
195-
196-
item->client = i2c_new_device(item->adapter, &item->brdinfo);
197-
if (!item->client) {
198-
dev_err(dev, "Failed to create client %s at bus %d at addr 0x%02x\n",
199-
item->brdinfo.type, item->nr, item->brdinfo.addr);
200-
i2c_put_adapter(item->adapter);
201-
item->adapter = NULL;
202-
return -EFAULT;
203-
}
204-
205-
return 0;
206-
}
207-
208-
static void mlxreg_hotplug_device_destroy(struct mlxreg_hotplug_device *item)
209-
{
210-
if (item->client) {
211-
i2c_unregister_device(item->client);
212-
item->client = NULL;
213-
}
214-
215-
if (item->adapter) {
216-
i2c_put_adapter(item->adapter);
217-
item->adapter = NULL;
218-
}
219-
}
220-
221221
static inline void
222222
mlxreg_hotplug_work_helper(struct device *dev,
223223
struct mlxreg_hotplug_device *item, u8 is_inverse,

0 commit comments

Comments
 (0)