static int w1_family_notify()

in w1.c [616:672]


static int w1_family_notify(unsigned long action, struct w1_slave *sl)
{
	const struct w1_family_ops *fops;
	int err;

	fops = sl->family->fops;

	if (!fops)
		return 0;

	switch (action) {
	case BUS_NOTIFY_ADD_DEVICE:
		/* if the family driver needs to initialize something... */
		if (fops->add_slave) {
			err = fops->add_slave(sl);
			if (err < 0) {
				dev_err(&sl->dev,
					"add_slave() call failed. err=%d\n",
					err);
				return err;
			}
		}
		if (fops->groups) {
			err = sysfs_create_groups(&sl->dev.kobj, fops->groups);
			if (err) {
				dev_err(&sl->dev,
					"sysfs group creation failed. err=%d\n",
					err);
				return err;
			}
		}
		if (IS_REACHABLE(CONFIG_HWMON) && fops->chip_info) {
			struct device *hwmon
				= hwmon_device_register_with_info(&sl->dev,
						"w1_slave_temp", sl,
						fops->chip_info,
						NULL);
			if (IS_ERR(hwmon)) {
				dev_warn(&sl->dev,
					 "could not create hwmon device\n");
			} else {
				sl->hwmon = hwmon;
			}
		}
		break;
	case BUS_NOTIFY_DEL_DEVICE:
		if (IS_REACHABLE(CONFIG_HWMON) && fops->chip_info &&
			    sl->hwmon)
			hwmon_device_unregister(sl->hwmon);
		if (fops->remove_slave)
			sl->family->fops->remove_slave(sl);
		if (fops->groups)
			sysfs_remove_groups(&sl->dev.kobj, fops->groups);
		break;
	}
	return 0;
}