openprom.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. * Linux/SPARC PROM Configuration Driver
  3. * Copyright (C) 1996 Thomas K. Dyas (tdyas@noc.rutgers.edu)
  4. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  5. *
  6. * This character device driver allows user programs to access the
  7. * PROM device tree. It is compatible with the SunOS /dev/openprom
  8. * driver and the NetBSD /dev/openprom driver. The SunOS eeprom
  9. * utility works without any modifications.
  10. *
  11. * The driver uses a minor number under the misc device major. The
  12. * file read/write mode determines the type of access to the PROM.
  13. * Interrupts are disabled whenever the driver calls into the PROM for
  14. * sanity's sake.
  15. */
  16. /* This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of the
  19. * License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful, but
  22. * WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. * General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. */
  30. #include <linux/module.h>
  31. #include <linux/kernel.h>
  32. #include <linux/errno.h>
  33. #include <linux/slab.h>
  34. #include <linux/mutex.h>
  35. #include <linux/string.h>
  36. #include <linux/miscdevice.h>
  37. #include <linux/init.h>
  38. #include <linux/fs.h>
  39. #include <asm/oplib.h>
  40. #include <asm/prom.h>
  41. #include <asm/system.h>
  42. #include <asm/uaccess.h>
  43. #include <asm/openpromio.h>
  44. #ifdef CONFIG_PCI
  45. #include <linux/pci.h>
  46. #endif
  47. MODULE_AUTHOR("Thomas K. Dyas (tdyas@noc.rutgers.edu) and Eddie C. Dost (ecd@skynet.be)");
  48. MODULE_DESCRIPTION("OPENPROM Configuration Driver");
  49. MODULE_LICENSE("GPL");
  50. MODULE_VERSION("1.0");
  51. MODULE_ALIAS_MISCDEV(SUN_OPENPROM_MINOR);
  52. /* Private data kept by the driver for each descriptor. */
  53. typedef struct openprom_private_data
  54. {
  55. struct device_node *current_node; /* Current node for SunOS ioctls. */
  56. struct device_node *lastnode; /* Last valid node used by BSD ioctls. */
  57. } DATA;
  58. /* ID of the PROM node containing all of the EEPROM options. */
  59. static DEFINE_MUTEX(openprom_mutex);
  60. static struct device_node *options_node;
  61. /*
  62. * Copy an openpromio structure into kernel space from user space.
  63. * This routine does error checking to make sure that all memory
  64. * accesses are within bounds. A pointer to the allocated openpromio
  65. * structure will be placed in "*opp_p". Return value is the length
  66. * of the user supplied buffer.
  67. */
  68. static int copyin(struct openpromio __user *info, struct openpromio **opp_p)
  69. {
  70. unsigned int bufsize;
  71. if (!info || !opp_p)
  72. return -EFAULT;
  73. if (get_user(bufsize, &info->oprom_size))
  74. return -EFAULT;
  75. if (bufsize == 0)
  76. return -EINVAL;
  77. /* If the bufsize is too large, just limit it.
  78. * Fix from Jason Rappleye.
  79. */
  80. if (bufsize > OPROMMAXPARAM)
  81. bufsize = OPROMMAXPARAM;
  82. if (!(*opp_p = kzalloc(sizeof(int) + bufsize + 1, GFP_KERNEL)))
  83. return -ENOMEM;
  84. if (copy_from_user(&(*opp_p)->oprom_array,
  85. &info->oprom_array, bufsize)) {
  86. kfree(*opp_p);
  87. return -EFAULT;
  88. }
  89. return bufsize;
  90. }
  91. static int getstrings(struct openpromio __user *info, struct openpromio **opp_p)
  92. {
  93. int n, bufsize;
  94. char c;
  95. if (!info || !opp_p)
  96. return -EFAULT;
  97. if (!(*opp_p = kzalloc(sizeof(int) + OPROMMAXPARAM + 1, GFP_KERNEL)))
  98. return -ENOMEM;
  99. (*opp_p)->oprom_size = 0;
  100. n = bufsize = 0;
  101. while ((n < 2) && (bufsize < OPROMMAXPARAM)) {
  102. if (get_user(c, &info->oprom_array[bufsize])) {
  103. kfree(*opp_p);
  104. return -EFAULT;
  105. }
  106. if (c == '\0')
  107. n++;
  108. (*opp_p)->oprom_array[bufsize++] = c;
  109. }
  110. if (!n) {
  111. kfree(*opp_p);
  112. return -EINVAL;
  113. }
  114. return bufsize;
  115. }
  116. /*
  117. * Copy an openpromio structure in kernel space back to user space.
  118. */
  119. static int copyout(void __user *info, struct openpromio *opp, int len)
  120. {
  121. if (copy_to_user(info, opp, len))
  122. return -EFAULT;
  123. return 0;
  124. }
  125. static int opromgetprop(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize)
  126. {
  127. const void *pval;
  128. int len;
  129. if (!dp ||
  130. !(pval = of_get_property(dp, op->oprom_array, &len)) ||
  131. len <= 0 || len > bufsize)
  132. return copyout(argp, op, sizeof(int));
  133. memcpy(op->oprom_array, pval, len);
  134. op->oprom_array[len] = '\0';
  135. op->oprom_size = len;
  136. return copyout(argp, op, sizeof(int) + bufsize);
  137. }
  138. static int opromnxtprop(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize)
  139. {
  140. struct property *prop;
  141. int len;
  142. if (!dp)
  143. return copyout(argp, op, sizeof(int));
  144. if (op->oprom_array[0] == '\0') {
  145. prop = dp->properties;
  146. if (!prop)
  147. return copyout(argp, op, sizeof(int));
  148. len = strlen(prop->name);
  149. } else {
  150. prop = of_find_property(dp, op->oprom_array, NULL);
  151. if (!prop ||
  152. !prop->next ||
  153. (len = strlen(prop->next->name)) + 1 > bufsize)
  154. return copyout(argp, op, sizeof(int));
  155. prop = prop->next;
  156. }
  157. memcpy(op->oprom_array, prop->name, len);
  158. op->oprom_array[len] = '\0';
  159. op->oprom_size = ++len;
  160. return copyout(argp, op, sizeof(int) + bufsize);
  161. }
  162. static int opromsetopt(struct device_node *dp, struct openpromio *op, int bufsize)
  163. {
  164. char *buf = op->oprom_array + strlen(op->oprom_array) + 1;
  165. int len = op->oprom_array + bufsize - buf;
  166. return of_set_property(options_node, op->oprom_array, buf, len);
  167. }
  168. static int opromnext(void __user *argp, unsigned int cmd, struct device_node *dp, struct openpromio *op, int bufsize, DATA *data)
  169. {
  170. phandle ph;
  171. BUILD_BUG_ON(sizeof(phandle) != sizeof(int));
  172. if (bufsize < sizeof(phandle))
  173. return -EINVAL;
  174. ph = *((int *) op->oprom_array);
  175. if (ph) {
  176. dp = of_find_node_by_phandle(ph);
  177. if (!dp)
  178. return -EINVAL;
  179. switch (cmd) {
  180. case OPROMNEXT:
  181. dp = dp->sibling;
  182. break;
  183. case OPROMCHILD:
  184. dp = dp->child;
  185. break;
  186. case OPROMSETCUR:
  187. default:
  188. break;
  189. };
  190. } else {
  191. /* Sibling of node zero is the root node. */
  192. if (cmd != OPROMNEXT)
  193. return -EINVAL;
  194. dp = of_find_node_by_path("/");
  195. }
  196. ph = 0;
  197. if (dp)
  198. ph = dp->phandle;
  199. data->current_node = dp;
  200. *((int *) op->oprom_array) = ph;
  201. op->oprom_size = sizeof(phandle);
  202. return copyout(argp, op, bufsize + sizeof(int));
  203. }
  204. static int oprompci2node(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize, DATA *data)
  205. {
  206. int err = -EINVAL;
  207. if (bufsize >= 2*sizeof(int)) {
  208. #ifdef CONFIG_PCI
  209. struct pci_dev *pdev;
  210. struct device_node *dp;
  211. pdev = pci_get_bus_and_slot (((int *) op->oprom_array)[0],
  212. ((int *) op->oprom_array)[1]);
  213. dp = pci_device_to_OF_node(pdev);
  214. data->current_node = dp;
  215. *((int *)op->oprom_array) = dp->phandle;
  216. op->oprom_size = sizeof(int);
  217. err = copyout(argp, op, bufsize + sizeof(int));
  218. pci_dev_put(pdev);
  219. #endif
  220. }
  221. return err;
  222. }
  223. static int oprompath2node(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize, DATA *data)
  224. {
  225. phandle ph = 0;
  226. dp = of_find_node_by_path(op->oprom_array);
  227. if (dp)
  228. ph = dp->phandle;
  229. data->current_node = dp;
  230. *((int *)op->oprom_array) = ph;
  231. op->oprom_size = sizeof(int);
  232. return copyout(argp, op, bufsize + sizeof(int));
  233. }
  234. static int opromgetbootargs(void __user *argp, struct openpromio *op, int bufsize)
  235. {
  236. char *buf = saved_command_line;
  237. int len = strlen(buf);
  238. if (len > bufsize)
  239. return -EINVAL;
  240. strcpy(op->oprom_array, buf);
  241. op->oprom_size = len;
  242. return copyout(argp, op, bufsize + sizeof(int));
  243. }
  244. /*
  245. * SunOS and Solaris /dev/openprom ioctl calls.
  246. */
  247. static long openprom_sunos_ioctl(struct file * file,
  248. unsigned int cmd, unsigned long arg,
  249. struct device_node *dp)
  250. {
  251. DATA *data = file->private_data;
  252. struct openpromio *opp = NULL;
  253. int bufsize, error = 0;
  254. static int cnt;
  255. void __user *argp = (void __user *)arg;
  256. if (cmd == OPROMSETOPT)
  257. bufsize = getstrings(argp, &opp);
  258. else
  259. bufsize = copyin(argp, &opp);
  260. if (bufsize < 0)
  261. return bufsize;
  262. mutex_lock(&openprom_mutex);
  263. switch (cmd) {
  264. case OPROMGETOPT:
  265. case OPROMGETPROP:
  266. error = opromgetprop(argp, dp, opp, bufsize);
  267. break;
  268. case OPROMNXTOPT:
  269. case OPROMNXTPROP:
  270. error = opromnxtprop(argp, dp, opp, bufsize);
  271. break;
  272. case OPROMSETOPT:
  273. case OPROMSETOPT2:
  274. error = opromsetopt(dp, opp, bufsize);
  275. break;
  276. case OPROMNEXT:
  277. case OPROMCHILD:
  278. case OPROMSETCUR:
  279. error = opromnext(argp, cmd, dp, opp, bufsize, data);
  280. break;
  281. case OPROMPCI2NODE:
  282. error = oprompci2node(argp, dp, opp, bufsize, data);
  283. break;
  284. case OPROMPATH2NODE:
  285. error = oprompath2node(argp, dp, opp, bufsize, data);
  286. break;
  287. case OPROMGETBOOTARGS:
  288. error = opromgetbootargs(argp, opp, bufsize);
  289. break;
  290. case OPROMU2P:
  291. case OPROMGETCONS:
  292. case OPROMGETFBNAME:
  293. if (cnt++ < 10)
  294. printk(KERN_INFO "openprom_sunos_ioctl: unimplemented ioctl\n");
  295. error = -EINVAL;
  296. break;
  297. default:
  298. if (cnt++ < 10)
  299. printk(KERN_INFO "openprom_sunos_ioctl: cmd 0x%X, arg 0x%lX\n", cmd, arg);
  300. error = -EINVAL;
  301. break;
  302. }
  303. kfree(opp);
  304. mutex_unlock(&openprom_mutex);
  305. return error;
  306. }
  307. static struct device_node *get_node(phandle n, DATA *data)
  308. {
  309. struct device_node *dp = of_find_node_by_phandle(n);
  310. if (dp)
  311. data->lastnode = dp;
  312. return dp;
  313. }
  314. /* Copy in a whole string from userspace into kernelspace. */
  315. static int copyin_string(char __user *user, size_t len, char **ptr)
  316. {
  317. char *tmp;
  318. if ((ssize_t)len < 0 || (ssize_t)(len + 1) < 0)
  319. return -EINVAL;
  320. tmp = kmalloc(len + 1, GFP_KERNEL);
  321. if (!tmp)
  322. return -ENOMEM;
  323. if (copy_from_user(tmp, user, len)) {
  324. kfree(tmp);
  325. return -EFAULT;
  326. }
  327. tmp[len] = '\0';
  328. *ptr = tmp;
  329. return 0;
  330. }
  331. /*
  332. * NetBSD /dev/openprom ioctl calls.
  333. */
  334. static int opiocget(void __user *argp, DATA *data)
  335. {
  336. struct opiocdesc op;
  337. struct device_node *dp;
  338. char *str;
  339. const void *pval;
  340. int err, len;
  341. if (copy_from_user(&op, argp, sizeof(op)))
  342. return -EFAULT;
  343. dp = get_node(op.op_nodeid, data);
  344. err = copyin_string(op.op_name, op.op_namelen, &str);
  345. if (err)
  346. return err;
  347. pval = of_get_property(dp, str, &len);
  348. err = 0;
  349. if (!pval || len > op.op_buflen) {
  350. err = -EINVAL;
  351. } else {
  352. op.op_buflen = len;
  353. if (copy_to_user(argp, &op, sizeof(op)) ||
  354. copy_to_user(op.op_buf, pval, len))
  355. err = -EFAULT;
  356. }
  357. kfree(str);
  358. return err;
  359. }
  360. static int opiocnextprop(void __user *argp, DATA *data)
  361. {
  362. struct opiocdesc op;
  363. struct device_node *dp;
  364. struct property *prop;
  365. char *str;
  366. int err, len;
  367. if (copy_from_user(&op, argp, sizeof(op)))
  368. return -EFAULT;
  369. dp = get_node(op.op_nodeid, data);
  370. if (!dp)
  371. return -EINVAL;
  372. err = copyin_string(op.op_name, op.op_namelen, &str);
  373. if (err)
  374. return err;
  375. if (str[0] == '\0') {
  376. prop = dp->properties;
  377. } else {
  378. prop = of_find_property(dp, str, NULL);
  379. if (prop)
  380. prop = prop->next;
  381. }
  382. kfree(str);
  383. if (!prop)
  384. len = 0;
  385. else
  386. len = prop->length;
  387. if (len > op.op_buflen)
  388. len = op.op_buflen;
  389. if (copy_to_user(argp, &op, sizeof(op)))
  390. return -EFAULT;
  391. if (len &&
  392. copy_to_user(op.op_buf, prop->value, len))
  393. return -EFAULT;
  394. return 0;
  395. }
  396. static int opiocset(void __user *argp, DATA *data)
  397. {
  398. struct opiocdesc op;
  399. struct device_node *dp;
  400. char *str, *tmp;
  401. int err;
  402. if (copy_from_user(&op, argp, sizeof(op)))
  403. return -EFAULT;
  404. dp = get_node(op.op_nodeid, data);
  405. if (!dp)
  406. return -EINVAL;
  407. err = copyin_string(op.op_name, op.op_namelen, &str);
  408. if (err)
  409. return err;
  410. err = copyin_string(op.op_buf, op.op_buflen, &tmp);
  411. if (err) {
  412. kfree(str);
  413. return err;
  414. }
  415. err = of_set_property(dp, str, tmp, op.op_buflen);
  416. kfree(str);
  417. kfree(tmp);
  418. return err;
  419. }
  420. static int opiocgetnext(unsigned int cmd, void __user *argp)
  421. {
  422. struct device_node *dp;
  423. phandle nd;
  424. BUILD_BUG_ON(sizeof(phandle) != sizeof(int));
  425. if (copy_from_user(&nd, argp, sizeof(phandle)))
  426. return -EFAULT;
  427. if (nd == 0) {
  428. if (cmd != OPIOCGETNEXT)
  429. return -EINVAL;
  430. dp = of_find_node_by_path("/");
  431. } else {
  432. dp = of_find_node_by_phandle(nd);
  433. nd = 0;
  434. if (dp) {
  435. if (cmd == OPIOCGETNEXT)
  436. dp = dp->sibling;
  437. else
  438. dp = dp->child;
  439. }
  440. }
  441. if (dp)
  442. nd = dp->phandle;
  443. if (copy_to_user(argp, &nd, sizeof(phandle)))
  444. return -EFAULT;
  445. return 0;
  446. }
  447. static int openprom_bsd_ioctl(struct file * file,
  448. unsigned int cmd, unsigned long arg)
  449. {
  450. DATA *data = file->private_data;
  451. void __user *argp = (void __user *)arg;
  452. int err;
  453. mutex_lock(&openprom_mutex);
  454. switch (cmd) {
  455. case OPIOCGET:
  456. err = opiocget(argp, data);
  457. break;
  458. case OPIOCNEXTPROP:
  459. err = opiocnextprop(argp, data);
  460. break;
  461. case OPIOCSET:
  462. err = opiocset(argp, data);
  463. break;
  464. case OPIOCGETOPTNODE:
  465. BUILD_BUG_ON(sizeof(phandle) != sizeof(int));
  466. err = 0;
  467. if (copy_to_user(argp, &options_node->phandle, sizeof(phandle)))
  468. err = -EFAULT;
  469. break;
  470. case OPIOCGETNEXT:
  471. case OPIOCGETCHILD:
  472. err = opiocgetnext(cmd, argp);
  473. break;
  474. default:
  475. err = -EINVAL;
  476. break;
  477. };
  478. mutex_unlock(&openprom_mutex);
  479. return err;
  480. }
  481. /*
  482. * Handoff control to the correct ioctl handler.
  483. */
  484. static long openprom_ioctl(struct file * file,
  485. unsigned int cmd, unsigned long arg)
  486. {
  487. DATA *data = file->private_data;
  488. switch (cmd) {
  489. case OPROMGETOPT:
  490. case OPROMNXTOPT:
  491. if ((file->f_mode & FMODE_READ) == 0)
  492. return -EPERM;
  493. return openprom_sunos_ioctl(file, cmd, arg,
  494. options_node);
  495. case OPROMSETOPT:
  496. case OPROMSETOPT2:
  497. if ((file->f_mode & FMODE_WRITE) == 0)
  498. return -EPERM;
  499. return openprom_sunos_ioctl(file, cmd, arg,
  500. options_node);
  501. case OPROMNEXT:
  502. case OPROMCHILD:
  503. case OPROMGETPROP:
  504. case OPROMNXTPROP:
  505. if ((file->f_mode & FMODE_READ) == 0)
  506. return -EPERM;
  507. return openprom_sunos_ioctl(file, cmd, arg,
  508. data->current_node);
  509. case OPROMU2P:
  510. case OPROMGETCONS:
  511. case OPROMGETFBNAME:
  512. case OPROMGETBOOTARGS:
  513. case OPROMSETCUR:
  514. case OPROMPCI2NODE:
  515. case OPROMPATH2NODE:
  516. if ((file->f_mode & FMODE_READ) == 0)
  517. return -EPERM;
  518. return openprom_sunos_ioctl(file, cmd, arg, NULL);
  519. case OPIOCGET:
  520. case OPIOCNEXTPROP:
  521. case OPIOCGETOPTNODE:
  522. case OPIOCGETNEXT:
  523. case OPIOCGETCHILD:
  524. if ((file->f_mode & FMODE_READ) == 0)
  525. return -EBADF;
  526. return openprom_bsd_ioctl(file,cmd,arg);
  527. case OPIOCSET:
  528. if ((file->f_mode & FMODE_WRITE) == 0)
  529. return -EBADF;
  530. return openprom_bsd_ioctl(file,cmd,arg);
  531. default:
  532. return -EINVAL;
  533. };
  534. }
  535. static long openprom_compat_ioctl(struct file *file, unsigned int cmd,
  536. unsigned long arg)
  537. {
  538. long rval = -ENOTTY;
  539. /*
  540. * SunOS/Solaris only, the NetBSD one's have embedded pointers in
  541. * the arg which we'd need to clean up...
  542. */
  543. switch (cmd) {
  544. case OPROMGETOPT:
  545. case OPROMSETOPT:
  546. case OPROMNXTOPT:
  547. case OPROMSETOPT2:
  548. case OPROMNEXT:
  549. case OPROMCHILD:
  550. case OPROMGETPROP:
  551. case OPROMNXTPROP:
  552. case OPROMU2P:
  553. case OPROMGETCONS:
  554. case OPROMGETFBNAME:
  555. case OPROMGETBOOTARGS:
  556. case OPROMSETCUR:
  557. case OPROMPCI2NODE:
  558. case OPROMPATH2NODE:
  559. rval = openprom_ioctl(file, cmd, arg);
  560. break;
  561. }
  562. return rval;
  563. }
  564. static int openprom_open(struct inode * inode, struct file * file)
  565. {
  566. DATA *data;
  567. data = kmalloc(sizeof(DATA), GFP_KERNEL);
  568. if (!data)
  569. return -ENOMEM;
  570. mutex_lock(&openprom_mutex);
  571. data->current_node = of_find_node_by_path("/");
  572. data->lastnode = data->current_node;
  573. file->private_data = (void *) data;
  574. mutex_unlock(&openprom_mutex);
  575. return 0;
  576. }
  577. static int openprom_release(struct inode * inode, struct file * file)
  578. {
  579. kfree(file->private_data);
  580. return 0;
  581. }
  582. static const struct file_operations openprom_fops = {
  583. .owner = THIS_MODULE,
  584. .llseek = no_llseek,
  585. .unlocked_ioctl = openprom_ioctl,
  586. .compat_ioctl = openprom_compat_ioctl,
  587. .open = openprom_open,
  588. .release = openprom_release,
  589. };
  590. static struct miscdevice openprom_dev = {
  591. .minor = SUN_OPENPROM_MINOR,
  592. .name = "openprom",
  593. .fops = &openprom_fops,
  594. };
  595. static int __init openprom_init(void)
  596. {
  597. struct device_node *dp;
  598. int err;
  599. err = misc_register(&openprom_dev);
  600. if (err)
  601. return err;
  602. dp = of_find_node_by_path("/");
  603. dp = dp->child;
  604. while (dp) {
  605. if (!strcmp(dp->name, "options"))
  606. break;
  607. dp = dp->sibling;
  608. }
  609. options_node = dp;
  610. if (!options_node) {
  611. misc_deregister(&openprom_dev);
  612. return -EIO;
  613. }
  614. return 0;
  615. }
  616. static void __exit openprom_cleanup(void)
  617. {
  618. misc_deregister(&openprom_dev);
  619. }
  620. module_init(openprom_init);
  621. module_exit(openprom_cleanup);