Skip to content

Commit 032c59c

Browse files
author
Tzung-Bi Shih
committed
platform/chrome: cros_ec_chardev: Decouple fops from struct cros_ec_dev
The fops doesn't really need to hold a reference to struct cros_ec_dev. Remove the references from the fops. No functional changes. Link: https://lore.kernel.org/r/20250721044456.2736300-4-tzungbi@kernel.org Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
1 parent 432418b commit 032c59c

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

drivers/platform/chrome/cros_ec_chardev.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
#define CROS_MAX_EVENT_LEN PAGE_SIZE
3333

3434
struct chardev_priv {
35-
struct cros_ec_dev *ec_dev;
35+
struct cros_ec_device *ec_dev;
3636
struct notifier_block notifier;
3737
wait_queue_head_t wait_event;
3838
unsigned long event_mask;
3939
struct list_head events;
4040
size_t event_len;
41+
u16 cmd_offset;
4142
};
4243

4344
struct ec_event {
@@ -47,7 +48,7 @@ struct ec_event {
4748
u8 data[];
4849
};
4950

50-
static int ec_get_version(struct cros_ec_dev *ec, char *str, int maxlen)
51+
static int ec_get_version(struct chardev_priv *priv, char *str, int maxlen)
5152
{
5253
static const char * const current_image_name[] = {
5354
"unknown", "read-only", "read-write", "invalid",
@@ -60,10 +61,10 @@ static int ec_get_version(struct cros_ec_dev *ec, char *str, int maxlen)
6061
if (!msg)
6162
return -ENOMEM;
6263

63-
msg->command = EC_CMD_GET_VERSION + ec->cmd_offset;
64+
msg->command = EC_CMD_GET_VERSION + priv->cmd_offset;
6465
msg->insize = sizeof(*resp);
6566

66-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
67+
ret = cros_ec_cmd_xfer_status(priv->ec_dev, msg);
6768
if (ret < 0) {
6869
snprintf(str, maxlen,
6970
"Unknown EC version, returned error: %d\n",
@@ -91,7 +92,7 @@ static int cros_ec_chardev_mkbp_event(struct notifier_block *nb,
9192
{
9293
struct chardev_priv *priv = container_of(nb, struct chardev_priv,
9394
notifier);
94-
struct cros_ec_device *ec_dev = priv->ec_dev->ec_dev;
95+
struct cros_ec_device *ec_dev = priv->ec_dev;
9596
struct ec_event *event;
9697
unsigned long event_bit = 1 << ec_dev->event_data.event_type;
9798
int total_size = sizeof(*event) + ec_dev->event_size;
@@ -156,7 +157,8 @@ static struct ec_event *cros_ec_chardev_fetch_event(struct chardev_priv *priv,
156157
static int cros_ec_chardev_open(struct inode *inode, struct file *filp)
157158
{
158159
struct miscdevice *mdev = filp->private_data;
159-
struct cros_ec_dev *ec_dev = dev_get_drvdata(mdev->parent);
160+
struct cros_ec_dev *ec = dev_get_drvdata(mdev->parent);
161+
struct cros_ec_device *ec_dev = ec->ec_dev;
160162
struct chardev_priv *priv;
161163
int ret;
162164

@@ -165,13 +167,14 @@ static int cros_ec_chardev_open(struct inode *inode, struct file *filp)
165167
return -ENOMEM;
166168

167169
priv->ec_dev = ec_dev;
170+
priv->cmd_offset = ec->cmd_offset;
168171
filp->private_data = priv;
169172
INIT_LIST_HEAD(&priv->events);
170173
init_waitqueue_head(&priv->wait_event);
171174
nonseekable_open(inode, filp);
172175

173176
priv->notifier.notifier_call = cros_ec_chardev_mkbp_event;
174-
ret = blocking_notifier_chain_register(&ec_dev->ec_dev->event_notifier,
177+
ret = blocking_notifier_chain_register(&ec_dev->event_notifier,
175178
&priv->notifier);
176179
if (ret) {
177180
dev_err(ec_dev->dev, "failed to register event notifier\n");
@@ -199,7 +202,6 @@ static ssize_t cros_ec_chardev_read(struct file *filp, char __user *buffer,
199202
char msg[sizeof(struct ec_response_get_version) +
200203
sizeof(CROS_EC_DEV_VERSION)];
201204
struct chardev_priv *priv = filp->private_data;
202-
struct cros_ec_dev *ec_dev = priv->ec_dev;
203205
size_t count;
204206
int ret;
205207

@@ -233,7 +235,7 @@ static ssize_t cros_ec_chardev_read(struct file *filp, char __user *buffer,
233235
if (*offset != 0)
234236
return 0;
235237

236-
ret = ec_get_version(ec_dev, msg, sizeof(msg));
238+
ret = ec_get_version(priv, msg, sizeof(msg));
237239
if (ret)
238240
return ret;
239241

@@ -249,10 +251,10 @@ static ssize_t cros_ec_chardev_read(struct file *filp, char __user *buffer,
249251
static int cros_ec_chardev_release(struct inode *inode, struct file *filp)
250252
{
251253
struct chardev_priv *priv = filp->private_data;
252-
struct cros_ec_dev *ec_dev = priv->ec_dev;
254+
struct cros_ec_device *ec_dev = priv->ec_dev;
253255
struct ec_event *event, *e;
254256

255-
blocking_notifier_chain_unregister(&ec_dev->ec_dev->event_notifier,
257+
blocking_notifier_chain_unregister(&ec_dev->event_notifier,
256258
&priv->notifier);
257259

258260
list_for_each_entry_safe(event, e, &priv->events, node) {
@@ -267,7 +269,7 @@ static int cros_ec_chardev_release(struct inode *inode, struct file *filp)
267269
/*
268270
* Ioctls
269271
*/
270-
static long cros_ec_chardev_ioctl_xcmd(struct cros_ec_dev *ec, void __user *arg)
272+
static long cros_ec_chardev_ioctl_xcmd(struct chardev_priv *priv, void __user *arg)
271273
{
272274
struct cros_ec_command *s_cmd;
273275
struct cros_ec_command u_cmd;
@@ -296,8 +298,8 @@ static long cros_ec_chardev_ioctl_xcmd(struct cros_ec_dev *ec, void __user *arg)
296298
goto exit;
297299
}
298300

299-
s_cmd->command += ec->cmd_offset;
300-
ret = cros_ec_cmd_xfer(ec->ec_dev, s_cmd);
301+
s_cmd->command += priv->cmd_offset;
302+
ret = cros_ec_cmd_xfer(priv->ec_dev, s_cmd);
301303
/* Only copy data to userland if data was received. */
302304
if (ret < 0)
303305
goto exit;
@@ -309,10 +311,9 @@ static long cros_ec_chardev_ioctl_xcmd(struct cros_ec_dev *ec, void __user *arg)
309311
return ret;
310312
}
311313

312-
static long cros_ec_chardev_ioctl_readmem(struct cros_ec_dev *ec,
313-
void __user *arg)
314+
static long cros_ec_chardev_ioctl_readmem(struct chardev_priv *priv, void __user *arg)
314315
{
315-
struct cros_ec_device *ec_dev = ec->ec_dev;
316+
struct cros_ec_device *ec_dev = priv->ec_dev;
316317
struct cros_ec_readmem s_mem = { };
317318
long num;
318319

@@ -341,16 +342,15 @@ static long cros_ec_chardev_ioctl(struct file *filp, unsigned int cmd,
341342
unsigned long arg)
342343
{
343344
struct chardev_priv *priv = filp->private_data;
344-
struct cros_ec_dev *ec = priv->ec_dev;
345345

346346
if (_IOC_TYPE(cmd) != CROS_EC_DEV_IOC)
347347
return -ENOTTY;
348348

349349
switch (cmd) {
350350
case CROS_EC_DEV_IOCXCMD:
351-
return cros_ec_chardev_ioctl_xcmd(ec, (void __user *)arg);
351+
return cros_ec_chardev_ioctl_xcmd(priv, (void __user *)arg);
352352
case CROS_EC_DEV_IOCRDMEM:
353-
return cros_ec_chardev_ioctl_readmem(ec, (void __user *)arg);
353+
return cros_ec_chardev_ioctl_readmem(priv, (void __user *)arg);
354354
case CROS_EC_DEV_IOCEVENTMASK:
355355
priv->event_mask = arg;
356356
return 0;
@@ -372,8 +372,8 @@ static const struct file_operations chardev_fops = {
372372

373373
static int cros_ec_chardev_probe(struct platform_device *pdev)
374374
{
375-
struct cros_ec_dev *ec_dev = dev_get_drvdata(pdev->dev.parent);
376-
struct cros_ec_platform *ec_platform = dev_get_platdata(ec_dev->dev);
375+
struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
376+
struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev);
377377
struct miscdevice *misc;
378378

379379
/* Create a char device: we want to create it anew */

0 commit comments

Comments
 (0)