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

Commit ea053b22 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Greg Kroah-Hartman
Browse files

ptp: create "pins" together with the rest of attributes



commit 85a66e55019583da1e0f18706b7a8281c9f6de5b upstream.

Let's switch to using device_create_with_groups(), which will allow us to
create "pins" attribute group together with the rest of ptp device
attributes, and before userspace gets notified about ptp device creation.

Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
[bwh: Backported to 4.9: adjust context]
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 6347abb8
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -214,16 +214,17 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
	mutex_init(&ptp->pincfg_mux);
	init_waitqueue_head(&ptp->tsev_wq);

	err = ptp_populate_pin_groups(ptp);
	if (err)
		goto no_pin_groups;

	/* Create a new device in our class. */
	ptp->dev = device_create(ptp_class, parent, ptp->devid, ptp,
	ptp->dev = device_create_with_groups(ptp_class, parent, ptp->devid,
					     ptp, ptp->pin_attr_groups,
					     "ptp%d", ptp->index);
	if (IS_ERR(ptp->dev))
		goto no_device;

	err = ptp_populate_sysfs(ptp);
	if (err)
		goto no_sysfs;

	/* Register a new PPS source. */
	if (info->pps) {
		struct pps_source_info pps;
@@ -251,10 +252,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
	if (ptp->pps_source)
		pps_unregister_source(ptp->pps_source);
no_pps:
	ptp_cleanup_sysfs(ptp);
no_sysfs:
	device_destroy(ptp_class, ptp->devid);
no_device:
	ptp_cleanup_pin_groups(ptp);
no_pin_groups:
	mutex_destroy(&ptp->tsevq_mux);
	mutex_destroy(&ptp->pincfg_mux);
	ida_simple_remove(&ptp_clocks_map, index);
@@ -273,8 +274,9 @@ int ptp_clock_unregister(struct ptp_clock *ptp)
	/* Release the clock's resources. */
	if (ptp->pps_source)
		pps_unregister_source(ptp->pps_source);
	ptp_cleanup_sysfs(ptp);

	device_destroy(ptp_class, ptp->devid);
	ptp_cleanup_pin_groups(ptp);

	posix_clock_unregister(&ptp->clock);
	return 0;
+4 −3
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ struct ptp_clock {
	struct device_attribute *pin_dev_attr;
	struct attribute **pin_attr;
	struct attribute_group pin_attr_group;
	/* 1st entry is a pointer to the real group, 2nd is NULL terminator */
	const struct attribute_group *pin_attr_groups[2];
};

/*
@@ -94,8 +96,7 @@ uint ptp_poll(struct posix_clock *pc,

extern const struct attribute_group *ptp_groups[];

int ptp_cleanup_sysfs(struct ptp_clock *ptp);

int ptp_populate_sysfs(struct ptp_clock *ptp);
int ptp_populate_pin_groups(struct ptp_clock *ptp);
void ptp_cleanup_pin_groups(struct ptp_clock *ptp);

#endif
+9 −30
Original line number Diff line number Diff line
@@ -268,24 +268,13 @@ static ssize_t ptp_pin_store(struct device *dev, struct device_attribute *attr,
	return count;
}

int ptp_cleanup_sysfs(struct ptp_clock *ptp)
int ptp_populate_pin_groups(struct ptp_clock *ptp)
{
	struct device *dev = ptp->dev;
	struct ptp_clock_info *info = ptp->info;
	int err = -ENOMEM, i, n_pins = info->n_pins;

	if (info->n_pins) {
		sysfs_remove_group(&dev->kobj, &ptp->pin_attr_group);
		kfree(ptp->pin_attr);
		kfree(ptp->pin_dev_attr);
	}
	if (!n_pins)
		return 0;
}

static int ptp_populate_pins(struct ptp_clock *ptp)
{
	struct device *dev = ptp->dev;
	struct ptp_clock_info *info = ptp->info;
	int err = -ENOMEM, i, n_pins = info->n_pins;

	ptp->pin_dev_attr = kzalloc(n_pins * sizeof(*ptp->pin_dev_attr),
				    GFP_KERNEL);
@@ -310,28 +299,18 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
	ptp->pin_attr_group.name = "pins";
	ptp->pin_attr_group.attrs = ptp->pin_attr;

	err = sysfs_create_group(&dev->kobj, &ptp->pin_attr_group);
	if (err)
		goto no_group;
	ptp->pin_attr_groups[0] = &ptp->pin_attr_group;

	return 0;

no_group:
	kfree(ptp->pin_attr);
no_pin_attr:
	kfree(ptp->pin_dev_attr);
no_dev_attr:
	return err;
}

int ptp_populate_sysfs(struct ptp_clock *ptp)
void ptp_cleanup_pin_groups(struct ptp_clock *ptp)
{
	struct ptp_clock_info *info = ptp->info;
	int err;

	if (info->n_pins) {
		err = ptp_populate_pins(ptp);
		if (err)
			return err;
	}
	return 0;
	kfree(ptp->pin_attr);
	kfree(ptp->pin_dev_attr);
}