ptp_chardev.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PTP 1588 clock support - character device implementation.
  4. *
  5. * Copyright (C) 2010 OMICRON electronics GmbH
  6. */
  7. #include <linux/compat.h>
  8. #include <linux/module.h>
  9. #include <linux/posix-clock.h>
  10. #include <linux/poll.h>
  11. #include <linux/sched.h>
  12. #include <linux/slab.h>
  13. #include <linux/timekeeping.h>
  14. #include <linux/debugfs.h>
  15. #include <linux/nospec.h>
  16. #include "ptp_private.h"
  17. static int ptp_disable_pinfunc(struct ptp_clock_info *ops,
  18. enum ptp_pin_function func, unsigned int chan)
  19. {
  20. struct ptp_clock_request rq;
  21. int err = 0;
  22. memset(&rq, 0, sizeof(rq));
  23. switch (func) {
  24. case PTP_PF_NONE:
  25. break;
  26. case PTP_PF_EXTTS:
  27. rq.type = PTP_CLK_REQ_EXTTS;
  28. rq.extts.index = chan;
  29. err = ops->enable(ops, &rq, 0);
  30. break;
  31. case PTP_PF_PEROUT:
  32. rq.type = PTP_CLK_REQ_PEROUT;
  33. rq.perout.index = chan;
  34. err = ops->enable(ops, &rq, 0);
  35. break;
  36. case PTP_PF_PHYSYNC:
  37. break;
  38. default:
  39. return -EINVAL;
  40. }
  41. return err;
  42. }
  43. int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin,
  44. enum ptp_pin_function func, unsigned int chan)
  45. {
  46. struct ptp_clock_info *info = ptp->info;
  47. struct ptp_pin_desc *pin1 = NULL, *pin2 = &info->pin_config[pin];
  48. unsigned int i;
  49. /* Check to see if any other pin previously had this function. */
  50. for (i = 0; i < info->n_pins; i++) {
  51. if (info->pin_config[i].func == func &&
  52. info->pin_config[i].chan == chan) {
  53. pin1 = &info->pin_config[i];
  54. break;
  55. }
  56. }
  57. if (pin1 && i == pin)
  58. return 0;
  59. /* Check the desired function and channel. */
  60. switch (func) {
  61. case PTP_PF_NONE:
  62. break;
  63. case PTP_PF_EXTTS:
  64. if (chan >= info->n_ext_ts)
  65. return -EINVAL;
  66. break;
  67. case PTP_PF_PEROUT:
  68. if (chan >= info->n_per_out)
  69. return -EINVAL;
  70. break;
  71. case PTP_PF_PHYSYNC:
  72. if (chan != 0)
  73. return -EINVAL;
  74. break;
  75. default:
  76. return -EINVAL;
  77. }
  78. if (info->verify(info, pin, func, chan)) {
  79. pr_err("driver cannot use function %u and channel %u on pin %u\n",
  80. func, chan, pin);
  81. return -EOPNOTSUPP;
  82. }
  83. /* Disable whatever function was previously assigned. */
  84. if (pin1) {
  85. ptp_disable_pinfunc(info, func, chan);
  86. pin1->func = PTP_PF_NONE;
  87. pin1->chan = 0;
  88. }
  89. ptp_disable_pinfunc(info, pin2->func, pin2->chan);
  90. pin2->func = func;
  91. pin2->chan = chan;
  92. return 0;
  93. }
  94. int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
  95. {
  96. struct ptp_clock *ptp =
  97. container_of(pccontext->clk, struct ptp_clock, clock);
  98. struct timestamp_event_queue *queue;
  99. char debugfsname[32];
  100. unsigned long flags;
  101. queue = kzalloc(sizeof(*queue), GFP_KERNEL);
  102. if (!queue)
  103. return -EINVAL;
  104. queue->mask = bitmap_alloc(PTP_MAX_CHANNELS, GFP_KERNEL);
  105. if (!queue->mask) {
  106. kfree(queue);
  107. return -EINVAL;
  108. }
  109. bitmap_set(queue->mask, 0, PTP_MAX_CHANNELS);
  110. spin_lock_init(&queue->lock);
  111. spin_lock_irqsave(&ptp->tsevqs_lock, flags);
  112. list_add_tail(&queue->qlist, &ptp->tsevqs);
  113. spin_unlock_irqrestore(&ptp->tsevqs_lock, flags);
  114. pccontext->private_clkdata = queue;
  115. /* Debugfs contents */
  116. sprintf(debugfsname, "0x%p", queue);
  117. queue->debugfs_instance =
  118. debugfs_create_dir(debugfsname, ptp->debugfs_root);
  119. queue->dfs_bitmap.array = (u32 *)queue->mask;
  120. queue->dfs_bitmap.n_elements =
  121. DIV_ROUND_UP(PTP_MAX_CHANNELS, BITS_PER_BYTE * sizeof(u32));
  122. debugfs_create_u32_array("mask", 0444, queue->debugfs_instance,
  123. &queue->dfs_bitmap);
  124. return 0;
  125. }
  126. int ptp_release(struct posix_clock_context *pccontext)
  127. {
  128. struct timestamp_event_queue *queue = pccontext->private_clkdata;
  129. unsigned long flags;
  130. struct ptp_clock *ptp =
  131. container_of(pccontext->clk, struct ptp_clock, clock);
  132. debugfs_remove(queue->debugfs_instance);
  133. pccontext->private_clkdata = NULL;
  134. spin_lock_irqsave(&ptp->tsevqs_lock, flags);
  135. list_del(&queue->qlist);
  136. spin_unlock_irqrestore(&ptp->tsevqs_lock, flags);
  137. bitmap_free(queue->mask);
  138. kfree(queue);
  139. return 0;
  140. }
  141. long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
  142. unsigned long arg)
  143. {
  144. struct ptp_clock *ptp =
  145. container_of(pccontext->clk, struct ptp_clock, clock);
  146. struct ptp_sys_offset_extended *extoff = NULL;
  147. struct ptp_sys_offset_precise precise_offset;
  148. struct system_device_crosststamp xtstamp;
  149. struct ptp_clock_info *ops = ptp->info;
  150. struct ptp_sys_offset *sysoff = NULL;
  151. struct timestamp_event_queue *tsevq;
  152. struct ptp_system_timestamp sts;
  153. struct ptp_clock_request req;
  154. struct ptp_clock_caps caps;
  155. struct ptp_clock_time *pct;
  156. unsigned int i, pin_index;
  157. struct ptp_pin_desc pd;
  158. struct timespec64 ts;
  159. int enable, err = 0;
  160. if (in_compat_syscall() && cmd != PTP_ENABLE_PPS && cmd != PTP_ENABLE_PPS2)
  161. arg = (unsigned long)compat_ptr(arg);
  162. tsevq = pccontext->private_clkdata;
  163. switch (cmd) {
  164. case PTP_CLOCK_GETCAPS:
  165. case PTP_CLOCK_GETCAPS2:
  166. memset(&caps, 0, sizeof(caps));
  167. caps.max_adj = ptp->info->max_adj;
  168. caps.n_alarm = ptp->info->n_alarm;
  169. caps.n_ext_ts = ptp->info->n_ext_ts;
  170. caps.n_per_out = ptp->info->n_per_out;
  171. caps.pps = ptp->info->pps;
  172. caps.n_pins = ptp->info->n_pins;
  173. caps.cross_timestamping = ptp->info->getcrosststamp != NULL;
  174. caps.adjust_phase = ptp->info->adjphase != NULL &&
  175. ptp->info->getmaxphase != NULL;
  176. if (caps.adjust_phase)
  177. caps.max_phase_adj = ptp->info->getmaxphase(ptp->info);
  178. if (copy_to_user((void __user *)arg, &caps, sizeof(caps)))
  179. err = -EFAULT;
  180. break;
  181. case PTP_EXTTS_REQUEST:
  182. case PTP_EXTTS_REQUEST2:
  183. memset(&req, 0, sizeof(req));
  184. if (copy_from_user(&req.extts, (void __user *)arg,
  185. sizeof(req.extts))) {
  186. err = -EFAULT;
  187. break;
  188. }
  189. if (cmd == PTP_EXTTS_REQUEST2) {
  190. /* Tell the drivers to check the flags carefully. */
  191. req.extts.flags |= PTP_STRICT_FLAGS;
  192. /* Make sure no reserved bit is set. */
  193. if ((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
  194. req.extts.rsv[0] || req.extts.rsv[1]) {
  195. err = -EINVAL;
  196. break;
  197. }
  198. /* Ensure one of the rising/falling edge bits is set. */
  199. if ((req.extts.flags & PTP_ENABLE_FEATURE) &&
  200. (req.extts.flags & PTP_EXTTS_EDGES) == 0) {
  201. err = -EINVAL;
  202. break;
  203. }
  204. } else if (cmd == PTP_EXTTS_REQUEST) {
  205. req.extts.flags &= PTP_EXTTS_V1_VALID_FLAGS;
  206. req.extts.rsv[0] = 0;
  207. req.extts.rsv[1] = 0;
  208. }
  209. if (req.extts.index >= ops->n_ext_ts) {
  210. err = -EINVAL;
  211. break;
  212. }
  213. req.type = PTP_CLK_REQ_EXTTS;
  214. enable = req.extts.flags & PTP_ENABLE_FEATURE ? 1 : 0;
  215. if (mutex_lock_interruptible(&ptp->pincfg_mux))
  216. return -ERESTARTSYS;
  217. err = ops->enable(ops, &req, enable);
  218. mutex_unlock(&ptp->pincfg_mux);
  219. break;
  220. case PTP_PEROUT_REQUEST:
  221. case PTP_PEROUT_REQUEST2:
  222. memset(&req, 0, sizeof(req));
  223. if (copy_from_user(&req.perout, (void __user *)arg,
  224. sizeof(req.perout))) {
  225. err = -EFAULT;
  226. break;
  227. }
  228. if (cmd == PTP_PEROUT_REQUEST2) {
  229. struct ptp_perout_request *perout = &req.perout;
  230. if (perout->flags & ~PTP_PEROUT_VALID_FLAGS) {
  231. err = -EINVAL;
  232. break;
  233. }
  234. /*
  235. * The "on" field has undefined meaning if
  236. * PTP_PEROUT_DUTY_CYCLE isn't set, we must still treat
  237. * it as reserved, which must be set to zero.
  238. */
  239. if (!(perout->flags & PTP_PEROUT_DUTY_CYCLE) &&
  240. (perout->rsv[0] || perout->rsv[1] ||
  241. perout->rsv[2] || perout->rsv[3])) {
  242. err = -EINVAL;
  243. break;
  244. }
  245. if (perout->flags & PTP_PEROUT_DUTY_CYCLE) {
  246. /* The duty cycle must be subunitary. */
  247. if (perout->on.sec > perout->period.sec ||
  248. (perout->on.sec == perout->period.sec &&
  249. perout->on.nsec > perout->period.nsec)) {
  250. err = -ERANGE;
  251. break;
  252. }
  253. }
  254. if (perout->flags & PTP_PEROUT_PHASE) {
  255. /*
  256. * The phase should be specified modulo the
  257. * period, therefore anything equal or larger
  258. * than 1 period is invalid.
  259. */
  260. if (perout->phase.sec > perout->period.sec ||
  261. (perout->phase.sec == perout->period.sec &&
  262. perout->phase.nsec >= perout->period.nsec)) {
  263. err = -ERANGE;
  264. break;
  265. }
  266. }
  267. } else if (cmd == PTP_PEROUT_REQUEST) {
  268. req.perout.flags &= PTP_PEROUT_V1_VALID_FLAGS;
  269. req.perout.rsv[0] = 0;
  270. req.perout.rsv[1] = 0;
  271. req.perout.rsv[2] = 0;
  272. req.perout.rsv[3] = 0;
  273. }
  274. if (req.perout.index >= ops->n_per_out) {
  275. err = -EINVAL;
  276. break;
  277. }
  278. req.type = PTP_CLK_REQ_PEROUT;
  279. enable = req.perout.period.sec || req.perout.period.nsec;
  280. if (mutex_lock_interruptible(&ptp->pincfg_mux))
  281. return -ERESTARTSYS;
  282. err = ops->enable(ops, &req, enable);
  283. mutex_unlock(&ptp->pincfg_mux);
  284. break;
  285. case PTP_ENABLE_PPS:
  286. case PTP_ENABLE_PPS2:
  287. memset(&req, 0, sizeof(req));
  288. if (!capable(CAP_SYS_TIME))
  289. return -EPERM;
  290. req.type = PTP_CLK_REQ_PPS;
  291. enable = arg ? 1 : 0;
  292. if (mutex_lock_interruptible(&ptp->pincfg_mux))
  293. return -ERESTARTSYS;
  294. err = ops->enable(ops, &req, enable);
  295. mutex_unlock(&ptp->pincfg_mux);
  296. break;
  297. case PTP_SYS_OFFSET_PRECISE:
  298. case PTP_SYS_OFFSET_PRECISE2:
  299. if (!ptp->info->getcrosststamp) {
  300. err = -EOPNOTSUPP;
  301. break;
  302. }
  303. err = ptp->info->getcrosststamp(ptp->info, &xtstamp);
  304. if (err)
  305. break;
  306. memset(&precise_offset, 0, sizeof(precise_offset));
  307. ts = ktime_to_timespec64(xtstamp.device);
  308. precise_offset.device.sec = ts.tv_sec;
  309. precise_offset.device.nsec = ts.tv_nsec;
  310. ts = ktime_to_timespec64(xtstamp.sys_realtime);
  311. precise_offset.sys_realtime.sec = ts.tv_sec;
  312. precise_offset.sys_realtime.nsec = ts.tv_nsec;
  313. ts = ktime_to_timespec64(xtstamp.sys_monoraw);
  314. precise_offset.sys_monoraw.sec = ts.tv_sec;
  315. precise_offset.sys_monoraw.nsec = ts.tv_nsec;
  316. if (copy_to_user((void __user *)arg, &precise_offset,
  317. sizeof(precise_offset)))
  318. err = -EFAULT;
  319. break;
  320. case PTP_SYS_OFFSET_EXTENDED:
  321. case PTP_SYS_OFFSET_EXTENDED2:
  322. if (!ptp->info->gettimex64) {
  323. err = -EOPNOTSUPP;
  324. break;
  325. }
  326. extoff = memdup_user((void __user *)arg, sizeof(*extoff));
  327. if (IS_ERR(extoff)) {
  328. err = PTR_ERR(extoff);
  329. extoff = NULL;
  330. break;
  331. }
  332. if (extoff->n_samples > PTP_MAX_SAMPLES ||
  333. extoff->rsv[0] || extoff->rsv[1] ||
  334. (extoff->clockid != CLOCK_REALTIME &&
  335. extoff->clockid != CLOCK_MONOTONIC &&
  336. extoff->clockid != CLOCK_MONOTONIC_RAW)) {
  337. err = -EINVAL;
  338. break;
  339. }
  340. sts.clockid = extoff->clockid;
  341. for (i = 0; i < extoff->n_samples; i++) {
  342. err = ptp->info->gettimex64(ptp->info, &ts, &sts);
  343. if (err)
  344. goto out;
  345. extoff->ts[i][0].sec = sts.pre_ts.tv_sec;
  346. extoff->ts[i][0].nsec = sts.pre_ts.tv_nsec;
  347. extoff->ts[i][1].sec = ts.tv_sec;
  348. extoff->ts[i][1].nsec = ts.tv_nsec;
  349. extoff->ts[i][2].sec = sts.post_ts.tv_sec;
  350. extoff->ts[i][2].nsec = sts.post_ts.tv_nsec;
  351. }
  352. if (copy_to_user((void __user *)arg, extoff, sizeof(*extoff)))
  353. err = -EFAULT;
  354. break;
  355. case PTP_SYS_OFFSET:
  356. case PTP_SYS_OFFSET2:
  357. sysoff = memdup_user((void __user *)arg, sizeof(*sysoff));
  358. if (IS_ERR(sysoff)) {
  359. err = PTR_ERR(sysoff);
  360. sysoff = NULL;
  361. break;
  362. }
  363. if (sysoff->n_samples > PTP_MAX_SAMPLES) {
  364. err = -EINVAL;
  365. break;
  366. }
  367. pct = &sysoff->ts[0];
  368. for (i = 0; i < sysoff->n_samples; i++) {
  369. ktime_get_real_ts64(&ts);
  370. pct->sec = ts.tv_sec;
  371. pct->nsec = ts.tv_nsec;
  372. pct++;
  373. if (ops->gettimex64)
  374. err = ops->gettimex64(ops, &ts, NULL);
  375. else
  376. err = ops->gettime64(ops, &ts);
  377. if (err)
  378. goto out;
  379. pct->sec = ts.tv_sec;
  380. pct->nsec = ts.tv_nsec;
  381. pct++;
  382. }
  383. ktime_get_real_ts64(&ts);
  384. pct->sec = ts.tv_sec;
  385. pct->nsec = ts.tv_nsec;
  386. if (copy_to_user((void __user *)arg, sysoff, sizeof(*sysoff)))
  387. err = -EFAULT;
  388. break;
  389. case PTP_PIN_GETFUNC:
  390. case PTP_PIN_GETFUNC2:
  391. if (copy_from_user(&pd, (void __user *)arg, sizeof(pd))) {
  392. err = -EFAULT;
  393. break;
  394. }
  395. if ((pd.rsv[0] || pd.rsv[1] || pd.rsv[2]
  396. || pd.rsv[3] || pd.rsv[4])
  397. && cmd == PTP_PIN_GETFUNC2) {
  398. err = -EINVAL;
  399. break;
  400. } else if (cmd == PTP_PIN_GETFUNC) {
  401. pd.rsv[0] = 0;
  402. pd.rsv[1] = 0;
  403. pd.rsv[2] = 0;
  404. pd.rsv[3] = 0;
  405. pd.rsv[4] = 0;
  406. }
  407. pin_index = pd.index;
  408. if (pin_index >= ops->n_pins) {
  409. err = -EINVAL;
  410. break;
  411. }
  412. pin_index = array_index_nospec(pin_index, ops->n_pins);
  413. if (mutex_lock_interruptible(&ptp->pincfg_mux))
  414. return -ERESTARTSYS;
  415. pd = ops->pin_config[pin_index];
  416. mutex_unlock(&ptp->pincfg_mux);
  417. if (!err && copy_to_user((void __user *)arg, &pd, sizeof(pd)))
  418. err = -EFAULT;
  419. break;
  420. case PTP_PIN_SETFUNC:
  421. case PTP_PIN_SETFUNC2:
  422. if (copy_from_user(&pd, (void __user *)arg, sizeof(pd))) {
  423. err = -EFAULT;
  424. break;
  425. }
  426. if ((pd.rsv[0] || pd.rsv[1] || pd.rsv[2]
  427. || pd.rsv[3] || pd.rsv[4])
  428. && cmd == PTP_PIN_SETFUNC2) {
  429. err = -EINVAL;
  430. break;
  431. } else if (cmd == PTP_PIN_SETFUNC) {
  432. pd.rsv[0] = 0;
  433. pd.rsv[1] = 0;
  434. pd.rsv[2] = 0;
  435. pd.rsv[3] = 0;
  436. pd.rsv[4] = 0;
  437. }
  438. pin_index = pd.index;
  439. if (pin_index >= ops->n_pins) {
  440. err = -EINVAL;
  441. break;
  442. }
  443. pin_index = array_index_nospec(pin_index, ops->n_pins);
  444. if (mutex_lock_interruptible(&ptp->pincfg_mux))
  445. return -ERESTARTSYS;
  446. err = ptp_set_pinfunc(ptp, pin_index, pd.func, pd.chan);
  447. mutex_unlock(&ptp->pincfg_mux);
  448. break;
  449. case PTP_MASK_CLEAR_ALL:
  450. bitmap_clear(tsevq->mask, 0, PTP_MAX_CHANNELS);
  451. break;
  452. case PTP_MASK_EN_SINGLE:
  453. if (copy_from_user(&i, (void __user *)arg, sizeof(i))) {
  454. err = -EFAULT;
  455. break;
  456. }
  457. if (i >= PTP_MAX_CHANNELS) {
  458. err = -EFAULT;
  459. break;
  460. }
  461. set_bit(i, tsevq->mask);
  462. break;
  463. default:
  464. err = -ENOTTY;
  465. break;
  466. }
  467. out:
  468. kfree(extoff);
  469. kfree(sysoff);
  470. return err;
  471. }
  472. __poll_t ptp_poll(struct posix_clock_context *pccontext, struct file *fp,
  473. poll_table *wait)
  474. {
  475. struct ptp_clock *ptp =
  476. container_of(pccontext->clk, struct ptp_clock, clock);
  477. struct timestamp_event_queue *queue;
  478. queue = pccontext->private_clkdata;
  479. if (!queue)
  480. return EPOLLERR;
  481. poll_wait(fp, &ptp->tsev_wq, wait);
  482. return queue_cnt(queue) ? EPOLLIN : 0;
  483. }
  484. #define EXTTS_BUFSIZE (PTP_BUF_TIMESTAMPS * sizeof(struct ptp_extts_event))
  485. ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags,
  486. char __user *buf, size_t cnt)
  487. {
  488. struct ptp_clock *ptp =
  489. container_of(pccontext->clk, struct ptp_clock, clock);
  490. struct timestamp_event_queue *queue;
  491. struct ptp_extts_event *event;
  492. unsigned long flags;
  493. size_t qcnt, i;
  494. int result;
  495. queue = pccontext->private_clkdata;
  496. if (!queue) {
  497. result = -EINVAL;
  498. goto exit;
  499. }
  500. if (cnt % sizeof(struct ptp_extts_event) != 0) {
  501. result = -EINVAL;
  502. goto exit;
  503. }
  504. if (cnt > EXTTS_BUFSIZE)
  505. cnt = EXTTS_BUFSIZE;
  506. cnt = cnt / sizeof(struct ptp_extts_event);
  507. if (wait_event_interruptible(ptp->tsev_wq,
  508. ptp->defunct || queue_cnt(queue))) {
  509. return -ERESTARTSYS;
  510. }
  511. if (ptp->defunct) {
  512. result = -ENODEV;
  513. goto exit;
  514. }
  515. event = kmalloc(EXTTS_BUFSIZE, GFP_KERNEL);
  516. if (!event) {
  517. result = -ENOMEM;
  518. goto exit;
  519. }
  520. spin_lock_irqsave(&queue->lock, flags);
  521. qcnt = queue_cnt(queue);
  522. if (cnt > qcnt)
  523. cnt = qcnt;
  524. for (i = 0; i < cnt; i++) {
  525. event[i] = queue->buf[queue->head];
  526. /* Paired with READ_ONCE() in queue_cnt() */
  527. WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS);
  528. }
  529. spin_unlock_irqrestore(&queue->lock, flags);
  530. cnt = cnt * sizeof(struct ptp_extts_event);
  531. result = cnt;
  532. if (copy_to_user(buf, event, cnt)) {
  533. result = -EFAULT;
  534. goto free_event;
  535. }
  536. free_event:
  537. kfree(event);
  538. exit:
  539. return result;
  540. }