[PATCH] isdn4linux: Gigaset driver: fix __must_check warning
[linux-block.git] / drivers / isdn / gigaset / proc.c
CommitLineData
982da5a1
HL
1/*
2 * Stuff used by all variants of the driver
3 *
70440cf2 4 * Copyright (c) 2001 by Stefan Eilers,
982da5a1
HL
5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>.
7 *
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
982da5a1
HL
14 */
15
16#include "gigaset.h"
17#include <linux/ctype.h>
18
3dda4e37 19static ssize_t show_cidmode(struct class_device *class, char *buf)
982da5a1 20{
69049cc8
TS
21 int ret;
22 unsigned long flags;
3dda4e37 23 struct cardstate *cs = class_get_devdata(class);
69049cc8
TS
24
25 spin_lock_irqsave(&cs->lock, flags);
26 ret = sprintf(buf, "%u\n", cs->cidmode);
27 spin_unlock_irqrestore(&cs->lock, flags);
28
29 return ret;
982da5a1
HL
30}
31
3dda4e37 32static ssize_t set_cidmode(struct class_device *class,
917f5085 33 const char *buf, size_t count)
982da5a1 34{
3dda4e37 35 struct cardstate *cs = class_get_devdata(class);
982da5a1
HL
36 long int value;
37 char *end;
38
39 value = simple_strtol(buf, &end, 0);
40 while (*end)
41 if (!isspace(*end++))
42 return -EINVAL;
43 if (value < 0 || value > 1)
44 return -EINVAL;
45
abfd1dc7 46 if (mutex_lock_interruptible(&cs->mutex))
982da5a1
HL
47 return -ERESTARTSYS; // FIXME -EINTR?
48
49 cs->waiting = 1;
50 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
784d5858 51 NULL, value, NULL)) {
982da5a1 52 cs->waiting = 0;
abfd1dc7 53 mutex_unlock(&cs->mutex);
982da5a1
HL
54 return -ENOMEM;
55 }
56
784d5858 57 gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
982da5a1
HL
58 gigaset_schedule_event(cs);
59
60 wait_event(cs->waitqueue, !cs->waiting);
61
abfd1dc7 62 mutex_unlock(&cs->mutex);
982da5a1
HL
63
64 return count;
65}
66
3dda4e37 67static CLASS_DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
982da5a1
HL
68
69/* free sysfs for device */
b1d47464 70void gigaset_free_dev_sysfs(struct cardstate *cs)
982da5a1 71{
3dda4e37
HL
72 if (!cs->class)
73 return;
74
784d5858 75 gig_dbg(DEBUG_INIT, "removing sysfs entries");
3dda4e37 76 class_device_remove_file(cs->class, &class_device_attr_cidmode);
982da5a1 77}
982da5a1
HL
78
79/* initialize sysfs for device */
b1d47464 80void gigaset_init_dev_sysfs(struct cardstate *cs)
982da5a1 81{
3dda4e37
HL
82 if (!cs->class)
83 return;
84
784d5858 85 gig_dbg(DEBUG_INIT, "setting up sysfs");
fd0fbcc2
TS
86 if (class_device_create_file(cs->class, &class_device_attr_cidmode))
87 dev_err(cs->dev, "could not create sysfs attribute\n");
982da5a1 88}