Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9bcf1266 authored by Chris Lew's avatar Chris Lew Committed by Gerrit - the friendly Code Review server
Browse files

rpmsg: glink: Fix character device allocation



RPMSG devices opened through the control device ioctl inherit the
rpmsg_device from the control device. The control device is not
initialized with a channel for the create_ept function. Initialize a
glink channel for the control device and remove the unneeded
structures for the character control device.

Change-Id: Ib5ce3e2297625d969931d2f166100b3381edbdca
Signed-off-by: default avatarChris Lew <clew@codeaurora.org>
parent 8bfc3881
Loading
Loading
Loading
Loading
+23 −24
Original line number Diff line number Diff line
@@ -159,13 +159,6 @@ enum {
	GLINK_STATE_CLOSING,
};

struct qcom_glink_device {
	struct rpmsg_device rpdev;
	struct qcom_glink *glink;
};

#define to_glink_device(_x) container_of(_x, struct qcom_glink_device, rpdev)

/**
 * struct glink_channel - internal representation of a channel
 * @rpdev:	rpdev reference, only used for primary endpoints
@@ -1289,7 +1282,7 @@ static int qcom_glink_announce_create(struct rpmsg_device *rpdev)
	__be32 *val = defaults;
	int size;

	if (glink->intentless)
	if (glink->intentless || !completion_done(&channel->open_ack))
		return 0;

	prop = of_find_property(np, "qcom,intents", NULL);
@@ -1490,10 +1483,6 @@ static struct device_node *qcom_glink_match_channel(struct device_node *node,
	return NULL;
}

static const struct rpmsg_device_ops glink_chrdev_ops = {
	.create_ept = qcom_glink_create_ept,
};

static const struct rpmsg_device_ops glink_device_ops = {
	.create_ept = qcom_glink_create_ept,
	.announce_create = qcom_glink_announce_create,
@@ -1714,9 +1703,9 @@ static ssize_t rpmsg_name_show(struct device *dev,
			       struct device_attribute *attr, char *buf)
{
	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
	struct qcom_glink_device *gdev = to_glink_device(rpdev);
	struct glink_channel *channel = to_glink_channel(rpdev->ept);

	return snprintf(buf, RPMSG_NAME_SIZE, "%s\n", gdev->glink->name);
	return snprintf(buf, RPMSG_NAME_SIZE, "%s\n", channel->glink->name);
}
static DEVICE_ATTR_RO(rpmsg_name);

@@ -1729,25 +1718,35 @@ ATTRIBUTE_GROUPS(qcom_glink);
static void qcom_glink_device_release(struct device *dev)
{
	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
	struct qcom_glink_device *gdev = to_glink_device(rpdev);
	struct glink_channel *channel = to_glink_channel(rpdev->ept);

	kfree(gdev);
	/* Release qcom_glink_alloc_channel() reference */
	kref_put(&channel->refcount, qcom_glink_channel_release);
	kfree(rpdev);
}

static int qcom_glink_create_chrdev(struct qcom_glink *glink)
{
	struct qcom_glink_device *gdev;
	struct rpmsg_device *rpdev;
	struct glink_channel *channel;

	gdev = kzalloc(sizeof(*gdev), GFP_KERNEL);
	if (!gdev)
	rpdev = kzalloc(sizeof(*rpdev), GFP_KERNEL);
	if (!rpdev)
		return -ENOMEM;

	gdev->glink = glink;
	gdev->rpdev.ops = &glink_chrdev_ops;
	gdev->rpdev.dev.parent = glink->dev;
	gdev->rpdev.dev.release = qcom_glink_device_release;
	channel = qcom_glink_alloc_channel(glink, "rpmsg_chrdev");
	if (IS_ERR(channel)) {
		kfree(rpdev);
		return PTR_ERR(channel);
	}
	channel->rpdev = rpdev;

	rpdev->ept = &channel->ept;
	rpdev->ops = &glink_device_ops;
	rpdev->dev.parent = glink->dev;
	rpdev->dev.release = qcom_glink_device_release;

	return rpmsg_chrdev_register_device(&gdev->rpdev);
	return rpmsg_chrdev_register_device(rpdev);
}

struct qcom_glink *qcom_glink_native_probe(struct device *dev,