core.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  1. /*
  2. * drivers/base/core.c - core driver model code (device registration, etc)
  3. *
  4. * Copyright (c) 2002-3 Patrick Mochel
  5. * Copyright (c) 2002-3 Open Source Development Labs
  6. * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
  7. * Copyright (c) 2006 Novell, Inc.
  8. *
  9. * This file is released under the GPLv2
  10. *
  11. */
  12. #include <linux/device.h>
  13. #include <linux/err.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/slab.h>
  17. #include <linux/string.h>
  18. #include <linux/kdev_t.h>
  19. #include <linux/notifier.h>
  20. #include <linux/genhd.h>
  21. #include <asm/semaphore.h>
  22. #include "base.h"
  23. #include "power/power.h"
  24. int (*platform_notify)(struct device *dev) = NULL;
  25. int (*platform_notify_remove)(struct device *dev) = NULL;
  26. #ifdef CONFIG_BLOCK
  27. static inline int device_is_not_partition(struct device *dev)
  28. {
  29. return !(dev->type == &part_type);
  30. }
  31. #else
  32. static inline int device_is_not_partition(struct device *dev)
  33. {
  34. return 1;
  35. }
  36. #endif
  37. /**
  38. * dev_driver_string - Return a device's driver name, if at all possible
  39. * @dev: struct device to get the name of
  40. *
  41. * Will return the device's driver's name if it is bound to a device. If
  42. * the device is not bound to a device, it will return the name of the bus
  43. * it is attached to. If it is not attached to a bus either, an empty
  44. * string will be returned.
  45. */
  46. const char *dev_driver_string(struct device *dev)
  47. {
  48. return dev->driver ? dev->driver->name :
  49. (dev->bus ? dev->bus->name :
  50. (dev->class ? dev->class->name : ""));
  51. }
  52. EXPORT_SYMBOL(dev_driver_string);
  53. #define to_dev(obj) container_of(obj, struct device, kobj)
  54. #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
  55. static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
  56. char *buf)
  57. {
  58. struct device_attribute *dev_attr = to_dev_attr(attr);
  59. struct device *dev = to_dev(kobj);
  60. ssize_t ret = -EIO;
  61. if (dev_attr->show)
  62. ret = dev_attr->show(dev, dev_attr, buf);
  63. return ret;
  64. }
  65. static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
  66. const char *buf, size_t count)
  67. {
  68. struct device_attribute *dev_attr = to_dev_attr(attr);
  69. struct device *dev = to_dev(kobj);
  70. ssize_t ret = -EIO;
  71. if (dev_attr->store)
  72. ret = dev_attr->store(dev, dev_attr, buf, count);
  73. return ret;
  74. }
  75. static struct sysfs_ops dev_sysfs_ops = {
  76. .show = dev_attr_show,
  77. .store = dev_attr_store,
  78. };
  79. /**
  80. * device_release - free device structure.
  81. * @kobj: device's kobject.
  82. *
  83. * This is called once the reference count for the object
  84. * reaches 0. We forward the call to the device's release
  85. * method, which should handle actually freeing the structure.
  86. */
  87. static void device_release(struct kobject *kobj)
  88. {
  89. struct device *dev = to_dev(kobj);
  90. if (dev->release)
  91. dev->release(dev);
  92. else if (dev->type && dev->type->release)
  93. dev->type->release(dev);
  94. else if (dev->class && dev->class->dev_release)
  95. dev->class->dev_release(dev);
  96. else {
  97. printk(KERN_ERR "Device '%s' does not have a release() "
  98. "function, it is broken and must be fixed.\n",
  99. dev->bus_id);
  100. WARN_ON(1);
  101. }
  102. }
  103. static struct kobj_type device_ktype = {
  104. .release = device_release,
  105. .sysfs_ops = &dev_sysfs_ops,
  106. };
  107. static int dev_uevent_filter(struct kset *kset, struct kobject *kobj)
  108. {
  109. struct kobj_type *ktype = get_ktype(kobj);
  110. if (ktype == &device_ktype) {
  111. struct device *dev = to_dev(kobj);
  112. if (dev->uevent_suppress)
  113. return 0;
  114. if (dev->bus)
  115. return 1;
  116. if (dev->class)
  117. return 1;
  118. }
  119. return 0;
  120. }
  121. static const char *dev_uevent_name(struct kset *kset, struct kobject *kobj)
  122. {
  123. struct device *dev = to_dev(kobj);
  124. if (dev->bus)
  125. return dev->bus->name;
  126. if (dev->class)
  127. return dev->class->name;
  128. return NULL;
  129. }
  130. static int dev_uevent(struct kset *kset, struct kobject *kobj,
  131. struct kobj_uevent_env *env)
  132. {
  133. struct device *dev = to_dev(kobj);
  134. int retval = 0;
  135. /* add the major/minor if present */
  136. if (MAJOR(dev->devt)) {
  137. add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt));
  138. add_uevent_var(env, "MINOR=%u", MINOR(dev->devt));
  139. }
  140. if (dev->type && dev->type->name)
  141. add_uevent_var(env, "DEVTYPE=%s", dev->type->name);
  142. if (dev->driver)
  143. add_uevent_var(env, "DRIVER=%s", dev->driver->name);
  144. #ifdef CONFIG_SYSFS_DEPRECATED
  145. if (dev->class) {
  146. struct device *parent = dev->parent;
  147. /* find first bus device in parent chain */
  148. while (parent && !parent->bus)
  149. parent = parent->parent;
  150. if (parent && parent->bus) {
  151. const char *path;
  152. path = kobject_get_path(&parent->kobj, GFP_KERNEL);
  153. if (path) {
  154. add_uevent_var(env, "PHYSDEVPATH=%s", path);
  155. kfree(path);
  156. }
  157. add_uevent_var(env, "PHYSDEVBUS=%s", parent->bus->name);
  158. if (parent->driver)
  159. add_uevent_var(env, "PHYSDEVDRIVER=%s",
  160. parent->driver->name);
  161. }
  162. } else if (dev->bus) {
  163. add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
  164. if (dev->driver)
  165. add_uevent_var(env, "PHYSDEVDRIVER=%s",
  166. dev->driver->name);
  167. }
  168. #endif
  169. /* have the bus specific function add its stuff */
  170. if (dev->bus && dev->bus->uevent) {
  171. retval = dev->bus->uevent(dev, env);
  172. if (retval)
  173. pr_debug("device: '%s': %s: bus uevent() returned %d\n",
  174. dev->bus_id, __FUNCTION__, retval);
  175. }
  176. /* have the class specific function add its stuff */
  177. if (dev->class && dev->class->dev_uevent) {
  178. retval = dev->class->dev_uevent(dev, env);
  179. if (retval)
  180. pr_debug("device: '%s': %s: class uevent() "
  181. "returned %d\n", dev->bus_id,
  182. __FUNCTION__, retval);
  183. }
  184. /* have the device type specific fuction add its stuff */
  185. if (dev->type && dev->type->uevent) {
  186. retval = dev->type->uevent(dev, env);
  187. if (retval)
  188. pr_debug("device: '%s': %s: dev_type uevent() "
  189. "returned %d\n", dev->bus_id,
  190. __FUNCTION__, retval);
  191. }
  192. return retval;
  193. }
  194. static struct kset_uevent_ops device_uevent_ops = {
  195. .filter = dev_uevent_filter,
  196. .name = dev_uevent_name,
  197. .uevent = dev_uevent,
  198. };
  199. static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
  200. char *buf)
  201. {
  202. struct kobject *top_kobj;
  203. struct kset *kset;
  204. struct kobj_uevent_env *env = NULL;
  205. int i;
  206. size_t count = 0;
  207. int retval;
  208. /* search the kset, the device belongs to */
  209. top_kobj = &dev->kobj;
  210. while (!top_kobj->kset && top_kobj->parent)
  211. top_kobj = top_kobj->parent;
  212. if (!top_kobj->kset)
  213. goto out;
  214. kset = top_kobj->kset;
  215. if (!kset->uevent_ops || !kset->uevent_ops->uevent)
  216. goto out;
  217. /* respect filter */
  218. if (kset->uevent_ops && kset->uevent_ops->filter)
  219. if (!kset->uevent_ops->filter(kset, &dev->kobj))
  220. goto out;
  221. env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
  222. if (!env)
  223. return -ENOMEM;
  224. /* let the kset specific function add its keys */
  225. retval = kset->uevent_ops->uevent(kset, &dev->kobj, env);
  226. if (retval)
  227. goto out;
  228. /* copy keys to file */
  229. for (i = 0; i < env->envp_idx; i++)
  230. count += sprintf(&buf[count], "%s\n", env->envp[i]);
  231. out:
  232. kfree(env);
  233. return count;
  234. }
  235. static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
  236. const char *buf, size_t count)
  237. {
  238. enum kobject_action action;
  239. if (kobject_action_type(buf, count, &action) == 0) {
  240. kobject_uevent(&dev->kobj, action);
  241. goto out;
  242. }
  243. dev_err(dev, "uevent: unsupported action-string; this will "
  244. "be ignored in a future kernel version\n");
  245. kobject_uevent(&dev->kobj, KOBJ_ADD);
  246. out:
  247. return count;
  248. }
  249. static struct device_attribute uevent_attr =
  250. __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent);
  251. static int device_add_attributes(struct device *dev,
  252. struct device_attribute *attrs)
  253. {
  254. int error = 0;
  255. int i;
  256. if (attrs) {
  257. for (i = 0; attr_name(attrs[i]); i++) {
  258. error = device_create_file(dev, &attrs[i]);
  259. if (error)
  260. break;
  261. }
  262. if (error)
  263. while (--i >= 0)
  264. device_remove_file(dev, &attrs[i]);
  265. }
  266. return error;
  267. }
  268. static void device_remove_attributes(struct device *dev,
  269. struct device_attribute *attrs)
  270. {
  271. int i;
  272. if (attrs)
  273. for (i = 0; attr_name(attrs[i]); i++)
  274. device_remove_file(dev, &attrs[i]);
  275. }
  276. static int device_add_groups(struct device *dev,
  277. struct attribute_group **groups)
  278. {
  279. int error = 0;
  280. int i;
  281. if (groups) {
  282. for (i = 0; groups[i]; i++) {
  283. error = sysfs_create_group(&dev->kobj, groups[i]);
  284. if (error) {
  285. while (--i >= 0)
  286. sysfs_remove_group(&dev->kobj,
  287. groups[i]);
  288. break;
  289. }
  290. }
  291. }
  292. return error;
  293. }
  294. static void device_remove_groups(struct device *dev,
  295. struct attribute_group **groups)
  296. {
  297. int i;
  298. if (groups)
  299. for (i = 0; groups[i]; i++)
  300. sysfs_remove_group(&dev->kobj, groups[i]);
  301. }
  302. static int device_add_attrs(struct device *dev)
  303. {
  304. struct class *class = dev->class;
  305. struct device_type *type = dev->type;
  306. int error;
  307. if (class) {
  308. error = device_add_attributes(dev, class->dev_attrs);
  309. if (error)
  310. return error;
  311. }
  312. if (type) {
  313. error = device_add_groups(dev, type->groups);
  314. if (error)
  315. goto err_remove_class_attrs;
  316. }
  317. error = device_add_groups(dev, dev->groups);
  318. if (error)
  319. goto err_remove_type_groups;
  320. return 0;
  321. err_remove_type_groups:
  322. if (type)
  323. device_remove_groups(dev, type->groups);
  324. err_remove_class_attrs:
  325. if (class)
  326. device_remove_attributes(dev, class->dev_attrs);
  327. return error;
  328. }
  329. static void device_remove_attrs(struct device *dev)
  330. {
  331. struct class *class = dev->class;
  332. struct device_type *type = dev->type;
  333. device_remove_groups(dev, dev->groups);
  334. if (type)
  335. device_remove_groups(dev, type->groups);
  336. if (class)
  337. device_remove_attributes(dev, class->dev_attrs);
  338. }
  339. static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
  340. char *buf)
  341. {
  342. return print_dev_t(buf, dev->devt);
  343. }
  344. static struct device_attribute devt_attr =
  345. __ATTR(dev, S_IRUGO, show_dev, NULL);
  346. /* kset to create /sys/devices/ */
  347. struct kset *devices_kset;
  348. /**
  349. * device_create_file - create sysfs attribute file for device.
  350. * @dev: device.
  351. * @attr: device attribute descriptor.
  352. */
  353. int device_create_file(struct device *dev, struct device_attribute *attr)
  354. {
  355. int error = 0;
  356. if (dev)
  357. error = sysfs_create_file(&dev->kobj, &attr->attr);
  358. return error;
  359. }
  360. /**
  361. * device_remove_file - remove sysfs attribute file.
  362. * @dev: device.
  363. * @attr: device attribute descriptor.
  364. */
  365. void device_remove_file(struct device *dev, struct device_attribute *attr)
  366. {
  367. if (dev)
  368. sysfs_remove_file(&dev->kobj, &attr->attr);
  369. }
  370. /**
  371. * device_create_bin_file - create sysfs binary attribute file for device.
  372. * @dev: device.
  373. * @attr: device binary attribute descriptor.
  374. */
  375. int device_create_bin_file(struct device *dev, struct bin_attribute *attr)
  376. {
  377. int error = -EINVAL;
  378. if (dev)
  379. error = sysfs_create_bin_file(&dev->kobj, attr);
  380. return error;
  381. }
  382. EXPORT_SYMBOL_GPL(device_create_bin_file);
  383. /**
  384. * device_remove_bin_file - remove sysfs binary attribute file
  385. * @dev: device.
  386. * @attr: device binary attribute descriptor.
  387. */
  388. void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
  389. {
  390. if (dev)
  391. sysfs_remove_bin_file(&dev->kobj, attr);
  392. }
  393. EXPORT_SYMBOL_GPL(device_remove_bin_file);
  394. /**
  395. * device_schedule_callback_owner - helper to schedule a callback for a device
  396. * @dev: device.
  397. * @func: callback function to invoke later.
  398. * @owner: module owning the callback routine
  399. *
  400. * Attribute methods must not unregister themselves or their parent device
  401. * (which would amount to the same thing). Attempts to do so will deadlock,
  402. * since unregistration is mutually exclusive with driver callbacks.
  403. *
  404. * Instead methods can call this routine, which will attempt to allocate
  405. * and schedule a workqueue request to call back @func with @dev as its
  406. * argument in the workqueue's process context. @dev will be pinned until
  407. * @func returns.
  408. *
  409. * This routine is usually called via the inline device_schedule_callback(),
  410. * which automatically sets @owner to THIS_MODULE.
  411. *
  412. * Returns 0 if the request was submitted, -ENOMEM if storage could not
  413. * be allocated, -ENODEV if a reference to @owner isn't available.
  414. *
  415. * NOTE: This routine won't work if CONFIG_SYSFS isn't set! It uses an
  416. * underlying sysfs routine (since it is intended for use by attribute
  417. * methods), and if sysfs isn't available you'll get nothing but -ENOSYS.
  418. */
  419. int device_schedule_callback_owner(struct device *dev,
  420. void (*func)(struct device *), struct module *owner)
  421. {
  422. return sysfs_schedule_callback(&dev->kobj,
  423. (void (*)(void *)) func, dev, owner);
  424. }
  425. EXPORT_SYMBOL_GPL(device_schedule_callback_owner);
  426. static void klist_children_get(struct klist_node *n)
  427. {
  428. struct device *dev = container_of(n, struct device, knode_parent);
  429. get_device(dev);
  430. }
  431. static void klist_children_put(struct klist_node *n)
  432. {
  433. struct device *dev = container_of(n, struct device, knode_parent);
  434. put_device(dev);
  435. }
  436. /**
  437. * device_initialize - init device structure.
  438. * @dev: device.
  439. *
  440. * This prepares the device for use by other layers,
  441. * including adding it to the device hierarchy.
  442. * It is the first half of device_register(), if called by
  443. * that, though it can also be called separately, so one
  444. * may use @dev's fields (e.g. the refcount).
  445. */
  446. void device_initialize(struct device *dev)
  447. {
  448. dev->kobj.kset = devices_kset;
  449. kobject_init(&dev->kobj, &device_ktype);
  450. klist_init(&dev->klist_children, klist_children_get,
  451. klist_children_put);
  452. INIT_LIST_HEAD(&dev->dma_pools);
  453. INIT_LIST_HEAD(&dev->node);
  454. init_MUTEX(&dev->sem);
  455. spin_lock_init(&dev->devres_lock);
  456. INIT_LIST_HEAD(&dev->devres_head);
  457. device_init_wakeup(dev, 0);
  458. set_dev_node(dev, -1);
  459. }
  460. #ifdef CONFIG_SYSFS_DEPRECATED
  461. static struct kobject *get_device_parent(struct device *dev,
  462. struct device *parent)
  463. {
  464. /* class devices without a parent live in /sys/class/<classname>/ */
  465. if (dev->class && (!parent || parent->class != dev->class))
  466. return &dev->class->subsys.kobj;
  467. /* all other devices keep their parent */
  468. else if (parent)
  469. return &parent->kobj;
  470. return NULL;
  471. }
  472. static inline void cleanup_device_parent(struct device *dev) {}
  473. static inline void cleanup_glue_dir(struct device *dev,
  474. struct kobject *glue_dir) {}
  475. #else
  476. static struct kobject *virtual_device_parent(struct device *dev)
  477. {
  478. static struct kobject *virtual_dir = NULL;
  479. if (!virtual_dir)
  480. virtual_dir = kobject_create_and_add("virtual",
  481. &devices_kset->kobj);
  482. return virtual_dir;
  483. }
  484. static struct kobject *get_device_parent(struct device *dev,
  485. struct device *parent)
  486. {
  487. int retval;
  488. if (dev->class) {
  489. struct kobject *kobj = NULL;
  490. struct kobject *parent_kobj;
  491. struct kobject *k;
  492. /*
  493. * If we have no parent, we live in "virtual".
  494. * Class-devices with a non class-device as parent, live
  495. * in a "glue" directory to prevent namespace collisions.
  496. */
  497. if (parent == NULL)
  498. parent_kobj = virtual_device_parent(dev);
  499. else if (parent->class)
  500. return &parent->kobj;
  501. else
  502. parent_kobj = &parent->kobj;
  503. /* find our class-directory at the parent and reference it */
  504. spin_lock(&dev->class->class_dirs.list_lock);
  505. list_for_each_entry(k, &dev->class->class_dirs.list, entry)
  506. if (k->parent == parent_kobj) {
  507. kobj = kobject_get(k);
  508. break;
  509. }
  510. spin_unlock(&dev->class->class_dirs.list_lock);
  511. if (kobj)
  512. return kobj;
  513. /* or create a new class-directory at the parent device */
  514. k = kobject_create();
  515. if (!k)
  516. return NULL;
  517. k->kset = &dev->class->class_dirs;
  518. retval = kobject_add(k, parent_kobj, "%s", dev->class->name);
  519. if (retval < 0) {
  520. kobject_put(k);
  521. return NULL;
  522. }
  523. /* do not emit an uevent for this simple "glue" directory */
  524. return k;
  525. }
  526. if (parent)
  527. return &parent->kobj;
  528. return NULL;
  529. }
  530. static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
  531. {
  532. /* see if we live in a "glue" directory */
  533. if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
  534. return;
  535. kobject_put(glue_dir);
  536. }
  537. static void cleanup_device_parent(struct device *dev)
  538. {
  539. cleanup_glue_dir(dev, dev->kobj.parent);
  540. }
  541. #endif
  542. static void setup_parent(struct device *dev, struct device *parent)
  543. {
  544. struct kobject *kobj;
  545. kobj = get_device_parent(dev, parent);
  546. if (kobj)
  547. dev->kobj.parent = kobj;
  548. }
  549. static int device_add_class_symlinks(struct device *dev)
  550. {
  551. int error;
  552. if (!dev->class)
  553. return 0;
  554. error = sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj,
  555. "subsystem");
  556. if (error)
  557. goto out;
  558. #ifdef CONFIG_SYSFS_DEPRECATED
  559. /* stacked class devices need a symlink in the class directory */
  560. if (dev->kobj.parent != &dev->class->subsys.kobj &&
  561. device_is_not_partition(dev)) {
  562. error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
  563. dev->bus_id);
  564. if (error)
  565. goto out_subsys;
  566. }
  567. if (dev->parent && device_is_not_partition(dev)) {
  568. struct device *parent = dev->parent;
  569. char *class_name;
  570. /*
  571. * stacked class devices have the 'device' link
  572. * pointing to the bus device instead of the parent
  573. */
  574. while (parent->class && !parent->bus && parent->parent)
  575. parent = parent->parent;
  576. error = sysfs_create_link(&dev->kobj,
  577. &parent->kobj,
  578. "device");
  579. if (error)
  580. goto out_busid;
  581. class_name = make_class_name(dev->class->name,
  582. &dev->kobj);
  583. if (class_name)
  584. error = sysfs_create_link(&dev->parent->kobj,
  585. &dev->kobj, class_name);
  586. kfree(class_name);
  587. if (error)
  588. goto out_device;
  589. }
  590. return 0;
  591. out_device:
  592. if (dev->parent && device_is_not_partition(dev))
  593. sysfs_remove_link(&dev->kobj, "device");
  594. out_busid:
  595. if (dev->kobj.parent != &dev->class->subsys.kobj &&
  596. device_is_not_partition(dev))
  597. sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
  598. #else
  599. /* link in the class directory pointing to the device */
  600. error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
  601. dev->bus_id);
  602. if (error)
  603. goto out_subsys;
  604. if (dev->parent && device_is_not_partition(dev)) {
  605. error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
  606. "device");
  607. if (error)
  608. goto out_busid;
  609. }
  610. return 0;
  611. out_busid:
  612. sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
  613. #endif
  614. out_subsys:
  615. sysfs_remove_link(&dev->kobj, "subsystem");
  616. out:
  617. return error;
  618. }
  619. static void device_remove_class_symlinks(struct device *dev)
  620. {
  621. if (!dev->class)
  622. return;
  623. #ifdef CONFIG_SYSFS_DEPRECATED
  624. if (dev->parent && device_is_not_partition(dev)) {
  625. char *class_name;
  626. class_name = make_class_name(dev->class->name, &dev->kobj);
  627. if (class_name) {
  628. sysfs_remove_link(&dev->parent->kobj, class_name);
  629. kfree(class_name);
  630. }
  631. sysfs_remove_link(&dev->kobj, "device");
  632. }
  633. if (dev->kobj.parent != &dev->class->subsys.kobj &&
  634. device_is_not_partition(dev))
  635. sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
  636. #else
  637. if (dev->parent && device_is_not_partition(dev))
  638. sysfs_remove_link(&dev->kobj, "device");
  639. sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
  640. #endif
  641. sysfs_remove_link(&dev->kobj, "subsystem");
  642. }
  643. /**
  644. * device_add - add device to device hierarchy.
  645. * @dev: device.
  646. *
  647. * This is part 2 of device_register(), though may be called
  648. * separately _iff_ device_initialize() has been called separately.
  649. *
  650. * This adds it to the kobject hierarchy via kobject_add(), adds it
  651. * to the global and sibling lists for the device, then
  652. * adds it to the other relevant subsystems of the driver model.
  653. */
  654. int device_add(struct device *dev)
  655. {
  656. struct device *parent = NULL;
  657. struct class_interface *class_intf;
  658. int error;
  659. error = pm_sleep_lock();
  660. if (error) {
  661. dev_warn(dev, "Suspicious %s during suspend\n", __FUNCTION__);
  662. dump_stack();
  663. return error;
  664. }
  665. dev = get_device(dev);
  666. if (!dev || !strlen(dev->bus_id)) {
  667. error = -EINVAL;
  668. goto Error;
  669. }
  670. pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
  671. parent = get_device(dev->parent);
  672. setup_parent(dev, parent);
  673. /* first, register with generic layer. */
  674. error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
  675. if (error)
  676. goto Error;
  677. /* notify platform of device entry */
  678. if (platform_notify)
  679. platform_notify(dev);
  680. /* notify clients of device entry (new way) */
  681. if (dev->bus)
  682. blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
  683. BUS_NOTIFY_ADD_DEVICE, dev);
  684. error = device_create_file(dev, &uevent_attr);
  685. if (error)
  686. goto attrError;
  687. if (MAJOR(dev->devt)) {
  688. error = device_create_file(dev, &devt_attr);
  689. if (error)
  690. goto ueventattrError;
  691. }
  692. error = device_add_class_symlinks(dev);
  693. if (error)
  694. goto SymlinkError;
  695. error = device_add_attrs(dev);
  696. if (error)
  697. goto AttrsError;
  698. error = dpm_sysfs_add(dev);
  699. if (error)
  700. goto PMError;
  701. device_pm_add(dev);
  702. error = bus_add_device(dev);
  703. if (error)
  704. goto BusError;
  705. kobject_uevent(&dev->kobj, KOBJ_ADD);
  706. bus_attach_device(dev);
  707. if (parent)
  708. klist_add_tail(&dev->knode_parent, &parent->klist_children);
  709. if (dev->class) {
  710. down(&dev->class->sem);
  711. /* tie the class to the device */
  712. list_add_tail(&dev->node, &dev->class->devices);
  713. /* notify any interfaces that the device is here */
  714. list_for_each_entry(class_intf, &dev->class->interfaces, node)
  715. if (class_intf->add_dev)
  716. class_intf->add_dev(dev, class_intf);
  717. up(&dev->class->sem);
  718. }
  719. Done:
  720. put_device(dev);
  721. pm_sleep_unlock();
  722. return error;
  723. BusError:
  724. device_pm_remove(dev);
  725. dpm_sysfs_remove(dev);
  726. PMError:
  727. if (dev->bus)
  728. blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
  729. BUS_NOTIFY_DEL_DEVICE, dev);
  730. device_remove_attrs(dev);
  731. AttrsError:
  732. device_remove_class_symlinks(dev);
  733. SymlinkError:
  734. if (MAJOR(dev->devt))
  735. device_remove_file(dev, &devt_attr);
  736. ueventattrError:
  737. device_remove_file(dev, &uevent_attr);
  738. attrError:
  739. kobject_uevent(&dev->kobj, KOBJ_REMOVE);
  740. kobject_del(&dev->kobj);
  741. Error:
  742. cleanup_device_parent(dev);
  743. if (parent)
  744. put_device(parent);
  745. goto Done;
  746. }
  747. /**
  748. * device_register - register a device with the system.
  749. * @dev: pointer to the device structure
  750. *
  751. * This happens in two clean steps - initialize the device
  752. * and add it to the system. The two steps can be called
  753. * separately, but this is the easiest and most common.
  754. * I.e. you should only call the two helpers separately if
  755. * have a clearly defined need to use and refcount the device
  756. * before it is added to the hierarchy.
  757. */
  758. int device_register(struct device *dev)
  759. {
  760. device_initialize(dev);
  761. return device_add(dev);
  762. }
  763. /**
  764. * get_device - increment reference count for device.
  765. * @dev: device.
  766. *
  767. * This simply forwards the call to kobject_get(), though
  768. * we do take care to provide for the case that we get a NULL
  769. * pointer passed in.
  770. */
  771. struct device *get_device(struct device *dev)
  772. {
  773. return dev ? to_dev(kobject_get(&dev->kobj)) : NULL;
  774. }
  775. /**
  776. * put_device - decrement reference count.
  777. * @dev: device in question.
  778. */
  779. void put_device(struct device *dev)
  780. {
  781. /* might_sleep(); */
  782. if (dev)
  783. kobject_put(&dev->kobj);
  784. }
  785. /**
  786. * device_del - delete device from system.
  787. * @dev: device.
  788. *
  789. * This is the first part of the device unregistration
  790. * sequence. This removes the device from the lists we control
  791. * from here, has it removed from the other driver model
  792. * subsystems it was added to in device_add(), and removes it
  793. * from the kobject hierarchy.
  794. *
  795. * NOTE: this should be called manually _iff_ device_add() was
  796. * also called manually.
  797. */
  798. void device_del(struct device *dev)
  799. {
  800. struct device *parent = dev->parent;
  801. struct class_interface *class_intf;
  802. device_pm_remove(dev);
  803. if (parent)
  804. klist_del(&dev->knode_parent);
  805. if (MAJOR(dev->devt))
  806. device_remove_file(dev, &devt_attr);
  807. if (dev->class) {
  808. device_remove_class_symlinks(dev);
  809. down(&dev->class->sem);
  810. /* notify any interfaces that the device is now gone */
  811. list_for_each_entry(class_intf, &dev->class->interfaces, node)
  812. if (class_intf->remove_dev)
  813. class_intf->remove_dev(dev, class_intf);
  814. /* remove the device from the class list */
  815. list_del_init(&dev->node);
  816. up(&dev->class->sem);
  817. }
  818. device_remove_file(dev, &uevent_attr);
  819. device_remove_attrs(dev);
  820. bus_remove_device(dev);
  821. /*
  822. * Some platform devices are driven without driver attached
  823. * and managed resources may have been acquired. Make sure
  824. * all resources are released.
  825. */
  826. devres_release_all(dev);
  827. /* Notify the platform of the removal, in case they
  828. * need to do anything...
  829. */
  830. if (platform_notify_remove)
  831. platform_notify_remove(dev);
  832. if (dev->bus)
  833. blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
  834. BUS_NOTIFY_DEL_DEVICE, dev);
  835. kobject_uevent(&dev->kobj, KOBJ_REMOVE);
  836. cleanup_device_parent(dev);
  837. kobject_del(&dev->kobj);
  838. put_device(parent);
  839. }
  840. /**
  841. * device_unregister - unregister device from system.
  842. * @dev: device going away.
  843. *
  844. * We do this in two parts, like we do device_register(). First,
  845. * we remove it from all the subsystems with device_del(), then
  846. * we decrement the reference count via put_device(). If that
  847. * is the final reference count, the device will be cleaned up
  848. * via device_release() above. Otherwise, the structure will
  849. * stick around until the final reference to the device is dropped.
  850. */
  851. void device_unregister(struct device *dev)
  852. {
  853. pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
  854. device_del(dev);
  855. put_device(dev);
  856. }
  857. static struct device *next_device(struct klist_iter *i)
  858. {
  859. struct klist_node *n = klist_next(i);
  860. return n ? container_of(n, struct device, knode_parent) : NULL;
  861. }
  862. /**
  863. * device_for_each_child - device child iterator.
  864. * @parent: parent struct device.
  865. * @data: data for the callback.
  866. * @fn: function to be called for each device.
  867. *
  868. * Iterate over @parent's child devices, and call @fn for each,
  869. * passing it @data.
  870. *
  871. * We check the return of @fn each time. If it returns anything
  872. * other than 0, we break out and return that value.
  873. */
  874. int device_for_each_child(struct device *parent, void *data,
  875. int (*fn)(struct device *dev, void *data))
  876. {
  877. struct klist_iter i;
  878. struct device *child;
  879. int error = 0;
  880. klist_iter_init(&parent->klist_children, &i);
  881. while ((child = next_device(&i)) && !error)
  882. error = fn(child, data);
  883. klist_iter_exit(&i);
  884. return error;
  885. }
  886. /**
  887. * device_find_child - device iterator for locating a particular device.
  888. * @parent: parent struct device
  889. * @data: Data to pass to match function
  890. * @match: Callback function to check device
  891. *
  892. * This is similar to the device_for_each_child() function above, but it
  893. * returns a reference to a device that is 'found' for later use, as
  894. * determined by the @match callback.
  895. *
  896. * The callback should return 0 if the device doesn't match and non-zero
  897. * if it does. If the callback returns non-zero and a reference to the
  898. * current device can be obtained, this function will return to the caller
  899. * and not iterate over any more devices.
  900. */
  901. struct device *device_find_child(struct device *parent, void *data,
  902. int (*match)(struct device *dev, void *data))
  903. {
  904. struct klist_iter i;
  905. struct device *child;
  906. if (!parent)
  907. return NULL;
  908. klist_iter_init(&parent->klist_children, &i);
  909. while ((child = next_device(&i)))
  910. if (match(child, data) && get_device(child))
  911. break;
  912. klist_iter_exit(&i);
  913. return child;
  914. }
  915. int __init devices_init(void)
  916. {
  917. devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
  918. if (!devices_kset)
  919. return -ENOMEM;
  920. return 0;
  921. }
  922. EXPORT_SYMBOL_GPL(device_for_each_child);
  923. EXPORT_SYMBOL_GPL(device_find_child);
  924. EXPORT_SYMBOL_GPL(device_initialize);
  925. EXPORT_SYMBOL_GPL(device_add);
  926. EXPORT_SYMBOL_GPL(device_register);
  927. EXPORT_SYMBOL_GPL(device_del);
  928. EXPORT_SYMBOL_GPL(device_unregister);
  929. EXPORT_SYMBOL_GPL(get_device);
  930. EXPORT_SYMBOL_GPL(put_device);
  931. EXPORT_SYMBOL_GPL(device_create_file);
  932. EXPORT_SYMBOL_GPL(device_remove_file);
  933. static void device_create_release(struct device *dev)
  934. {
  935. pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
  936. kfree(dev);
  937. }
  938. /**
  939. * device_create - creates a device and registers it with sysfs
  940. * @class: pointer to the struct class that this device should be registered to
  941. * @parent: pointer to the parent struct device of this new device, if any
  942. * @devt: the dev_t for the char device to be added
  943. * @fmt: string for the device's name
  944. *
  945. * This function can be used by char device classes. A struct device
  946. * will be created in sysfs, registered to the specified class.
  947. *
  948. * A "dev" file will be created, showing the dev_t for the device, if
  949. * the dev_t is not 0,0.
  950. * If a pointer to a parent struct device is passed in, the newly created
  951. * struct device will be a child of that device in sysfs.
  952. * The pointer to the struct device will be returned from the call.
  953. * Any further sysfs files that might be required can be created using this
  954. * pointer.
  955. *
  956. * Note: the struct class passed to this function must have previously
  957. * been created with a call to class_create().
  958. */
  959. struct device *device_create(struct class *class, struct device *parent,
  960. dev_t devt, const char *fmt, ...)
  961. {
  962. va_list args;
  963. struct device *dev = NULL;
  964. int retval = -ENODEV;
  965. if (class == NULL || IS_ERR(class))
  966. goto error;
  967. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  968. if (!dev) {
  969. retval = -ENOMEM;
  970. goto error;
  971. }
  972. dev->devt = devt;
  973. dev->class = class;
  974. dev->parent = parent;
  975. dev->release = device_create_release;
  976. va_start(args, fmt);
  977. vsnprintf(dev->bus_id, BUS_ID_SIZE, fmt, args);
  978. va_end(args);
  979. retval = device_register(dev);
  980. if (retval)
  981. goto error;
  982. return dev;
  983. error:
  984. kfree(dev);
  985. return ERR_PTR(retval);
  986. }
  987. EXPORT_SYMBOL_GPL(device_create);
  988. static int __match_devt(struct device *dev, void *data)
  989. {
  990. dev_t *devt = data;
  991. return dev->devt == *devt;
  992. }
  993. /**
  994. * device_destroy - removes a device that was created with device_create()
  995. * @class: pointer to the struct class that this device was registered with
  996. * @devt: the dev_t of the device that was previously registered
  997. *
  998. * This call unregisters and cleans up a device that was created with a
  999. * call to device_create().
  1000. */
  1001. void device_destroy(struct class *class, dev_t devt)
  1002. {
  1003. struct device *dev;
  1004. dev = class_find_device(class, &devt, __match_devt);
  1005. if (dev) {
  1006. put_device(dev);
  1007. device_unregister(dev);
  1008. }
  1009. }
  1010. EXPORT_SYMBOL_GPL(device_destroy);
  1011. #ifdef CONFIG_PM_SLEEP
  1012. /**
  1013. * destroy_suspended_device - asks the PM core to remove a suspended device
  1014. * @class: pointer to the struct class that this device was registered with
  1015. * @devt: the dev_t of the device that was previously registered
  1016. *
  1017. * This call notifies the PM core of the necessity to unregister a suspended
  1018. * device created with a call to device_create() (devices cannot be
  1019. * unregistered directly while suspended, since the PM core holds their
  1020. * semaphores at that time).
  1021. *
  1022. * It can only be called within the scope of a system sleep transition. In
  1023. * practice this means it has to be directly or indirectly invoked either by
  1024. * a suspend or resume method, or by the PM core (e.g. via
  1025. * disable_nonboot_cpus() or enable_nonboot_cpus()).
  1026. */
  1027. void destroy_suspended_device(struct class *class, dev_t devt)
  1028. {
  1029. struct device *dev;
  1030. dev = class_find_device(class, &devt, __match_devt);
  1031. if (dev) {
  1032. device_pm_schedule_removal(dev);
  1033. put_device(dev);
  1034. }
  1035. }
  1036. EXPORT_SYMBOL_GPL(destroy_suspended_device);
  1037. #endif /* CONFIG_PM_SLEEP */
  1038. /**
  1039. * device_rename - renames a device
  1040. * @dev: the pointer to the struct device to be renamed
  1041. * @new_name: the new name of the device
  1042. */
  1043. int device_rename(struct device *dev, char *new_name)
  1044. {
  1045. char *old_class_name = NULL;
  1046. char *new_class_name = NULL;
  1047. char *old_device_name = NULL;
  1048. int error;
  1049. dev = get_device(dev);
  1050. if (!dev)
  1051. return -EINVAL;
  1052. pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id,
  1053. __FUNCTION__, new_name);
  1054. #ifdef CONFIG_SYSFS_DEPRECATED
  1055. if ((dev->class) && (dev->parent))
  1056. old_class_name = make_class_name(dev->class->name, &dev->kobj);
  1057. #endif
  1058. old_device_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
  1059. if (!old_device_name) {
  1060. error = -ENOMEM;
  1061. goto out;
  1062. }
  1063. strlcpy(old_device_name, dev->bus_id, BUS_ID_SIZE);
  1064. strlcpy(dev->bus_id, new_name, BUS_ID_SIZE);
  1065. error = kobject_rename(&dev->kobj, new_name);
  1066. if (error) {
  1067. strlcpy(dev->bus_id, old_device_name, BUS_ID_SIZE);
  1068. goto out;
  1069. }
  1070. #ifdef CONFIG_SYSFS_DEPRECATED
  1071. if (old_class_name) {
  1072. new_class_name = make_class_name(dev->class->name, &dev->kobj);
  1073. if (new_class_name) {
  1074. error = sysfs_create_link(&dev->parent->kobj,
  1075. &dev->kobj, new_class_name);
  1076. if (error)
  1077. goto out;
  1078. sysfs_remove_link(&dev->parent->kobj, old_class_name);
  1079. }
  1080. }
  1081. #else
  1082. if (dev->class) {
  1083. sysfs_remove_link(&dev->class->subsys.kobj, old_device_name);
  1084. error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
  1085. dev->bus_id);
  1086. if (error) {
  1087. dev_err(dev, "%s: sysfs_create_symlink failed (%d)\n",
  1088. __FUNCTION__, error);
  1089. }
  1090. }
  1091. #endif
  1092. out:
  1093. put_device(dev);
  1094. kfree(new_class_name);
  1095. kfree(old_class_name);
  1096. kfree(old_device_name);
  1097. return error;
  1098. }
  1099. EXPORT_SYMBOL_GPL(device_rename);
  1100. static int device_move_class_links(struct device *dev,
  1101. struct device *old_parent,
  1102. struct device *new_parent)
  1103. {
  1104. int error = 0;
  1105. #ifdef CONFIG_SYSFS_DEPRECATED
  1106. char *class_name;
  1107. class_name = make_class_name(dev->class->name, &dev->kobj);
  1108. if (!class_name) {
  1109. error = -ENOMEM;
  1110. goto out;
  1111. }
  1112. if (old_parent) {
  1113. sysfs_remove_link(&dev->kobj, "device");
  1114. sysfs_remove_link(&old_parent->kobj, class_name);
  1115. }
  1116. if (new_parent) {
  1117. error = sysfs_create_link(&dev->kobj, &new_parent->kobj,
  1118. "device");
  1119. if (error)
  1120. goto out;
  1121. error = sysfs_create_link(&new_parent->kobj, &dev->kobj,
  1122. class_name);
  1123. if (error)
  1124. sysfs_remove_link(&dev->kobj, "device");
  1125. } else
  1126. error = 0;
  1127. out:
  1128. kfree(class_name);
  1129. return error;
  1130. #else
  1131. if (old_parent)
  1132. sysfs_remove_link(&dev->kobj, "device");
  1133. if (new_parent)
  1134. error = sysfs_create_link(&dev->kobj, &new_parent->kobj,
  1135. "device");
  1136. return error;
  1137. #endif
  1138. }
  1139. /**
  1140. * device_move - moves a device to a new parent
  1141. * @dev: the pointer to the struct device to be moved
  1142. * @new_parent: the new parent of the device (can by NULL)
  1143. */
  1144. int device_move(struct device *dev, struct device *new_parent)
  1145. {
  1146. int error;
  1147. struct device *old_parent;
  1148. struct kobject *new_parent_kobj;
  1149. dev = get_device(dev);
  1150. if (!dev)
  1151. return -EINVAL;
  1152. new_parent = get_device(new_parent);
  1153. new_parent_kobj = get_device_parent(dev, new_parent);
  1154. pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
  1155. __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
  1156. error = kobject_move(&dev->kobj, new_parent_kobj);
  1157. if (error) {
  1158. cleanup_glue_dir(dev, new_parent_kobj);
  1159. put_device(new_parent);
  1160. goto out;
  1161. }
  1162. old_parent = dev->parent;
  1163. dev->parent = new_parent;
  1164. if (old_parent)
  1165. klist_remove(&dev->knode_parent);
  1166. if (new_parent)
  1167. klist_add_tail(&dev->knode_parent, &new_parent->klist_children);
  1168. if (!dev->class)
  1169. goto out_put;
  1170. error = device_move_class_links(dev, old_parent, new_parent);
  1171. if (error) {
  1172. /* We ignore errors on cleanup since we're hosed anyway... */
  1173. device_move_class_links(dev, new_parent, old_parent);
  1174. if (!kobject_move(&dev->kobj, &old_parent->kobj)) {
  1175. if (new_parent)
  1176. klist_remove(&dev->knode_parent);
  1177. if (old_parent)
  1178. klist_add_tail(&dev->knode_parent,
  1179. &old_parent->klist_children);
  1180. }
  1181. cleanup_glue_dir(dev, new_parent_kobj);
  1182. put_device(new_parent);
  1183. goto out;
  1184. }
  1185. out_put:
  1186. put_device(old_parent);
  1187. out:
  1188. put_device(dev);
  1189. return error;
  1190. }
  1191. EXPORT_SYMBOL_GPL(device_move);
  1192. /**
  1193. * device_shutdown - call ->shutdown() on each device to shutdown.
  1194. */
  1195. void device_shutdown(void)
  1196. {
  1197. struct device *dev, *devn;
  1198. list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
  1199. kobj.entry) {
  1200. if (dev->bus && dev->bus->shutdown) {
  1201. dev_dbg(dev, "shutdown\n");
  1202. dev->bus->shutdown(dev);
  1203. } else if (dev->driver && dev->driver->shutdown) {
  1204. dev_dbg(dev, "shutdown\n");
  1205. dev->driver->shutdown(dev);
  1206. }
  1207. }
  1208. }