Lines Matching +full:error +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0-or-later
26 if (effect_id < 0 || effect_id >= ff->max_effects || in check_effect_access()
27 !ff->effect_owners[effect_id]) in check_effect_access()
28 return -EINVAL; in check_effect_access()
30 if (file && ff->effect_owners[effect_id] != file) in check_effect_access()
31 return -EACCES; in check_effect_access()
42 return e1->type == e2->type && in check_effects_compatible()
43 (e1->type != FF_PERIODIC || in check_effects_compatible()
44 e1->u.periodic.waveform == e2->u.periodic.waveform); in check_effects_compatible()
54 switch (effect->type) { in compat_effect()
56 if (!test_bit(FF_PERIODIC, ff->ffbit)) in compat_effect()
57 return -EINVAL; in compat_effect()
63 magnitude = effect->u.rumble.strong_magnitude / 3 + in compat_effect()
64 effect->u.rumble.weak_magnitude / 6; in compat_effect()
66 effect->type = FF_PERIODIC; in compat_effect()
67 effect->u.periodic.waveform = FF_SINE; in compat_effect()
68 effect->u.periodic.period = 50; in compat_effect()
69 effect->u.periodic.magnitude = magnitude; in compat_effect()
70 effect->u.periodic.offset = 0; in compat_effect()
71 effect->u.periodic.phase = 0; in compat_effect()
72 effect->u.periodic.envelope.attack_length = 0; in compat_effect()
73 effect->u.periodic.envelope.attack_level = 0; in compat_effect()
74 effect->u.periodic.envelope.fade_length = 0; in compat_effect()
75 effect->u.periodic.envelope.fade_level = 0; in compat_effect()
86 * input_ff_upload() - upload effect into force-feedback device
94 struct ff_device *ff = dev->ff; in input_ff_upload()
96 int error; in input_ff_upload() local
97 int id; in input_ff_upload() local
99 if (!test_bit(EV_FF, dev->evbit)) in input_ff_upload()
100 return -ENOSYS; in input_ff_upload()
102 if (effect->type < FF_EFFECT_MIN || effect->type > FF_EFFECT_MAX || in input_ff_upload()
103 !test_bit(effect->type, dev->ffbit)) { in input_ff_upload()
104 dev_dbg(&dev->dev, "invalid or not supported effect type in upload\n"); in input_ff_upload()
105 return -EINVAL; in input_ff_upload()
108 if (effect->type == FF_PERIODIC && in input_ff_upload()
109 (effect->u.periodic.waveform < FF_WAVEFORM_MIN || in input_ff_upload()
110 effect->u.periodic.waveform > FF_WAVEFORM_MAX || in input_ff_upload()
111 !test_bit(effect->u.periodic.waveform, dev->ffbit))) { in input_ff_upload()
112 dev_dbg(&dev->dev, "invalid or not supported wave form in upload\n"); in input_ff_upload()
113 return -EINVAL; in input_ff_upload()
116 if (!test_bit(effect->type, ff->ffbit)) { in input_ff_upload()
117 error = compat_effect(ff, effect); in input_ff_upload()
118 if (error) in input_ff_upload()
119 return error; in input_ff_upload()
122 guard(mutex)(&ff->mutex); in input_ff_upload()
124 if (effect->id == -1) { in input_ff_upload()
125 for (id = 0; id < ff->max_effects; id++) in input_ff_upload()
126 if (!ff->effect_owners[id]) in input_ff_upload()
129 if (id >= ff->max_effects) in input_ff_upload()
130 return -ENOSPC; in input_ff_upload()
132 effect->id = id; in input_ff_upload()
136 id = effect->id; in input_ff_upload()
138 error = check_effect_access(ff, id, file); in input_ff_upload()
139 if (error) in input_ff_upload()
140 return error; in input_ff_upload()
142 old = &ff->effects[id]; in input_ff_upload()
145 return -EINVAL; in input_ff_upload()
148 error = ff->upload(dev, effect, old); in input_ff_upload()
149 if (error) in input_ff_upload()
150 return error; in input_ff_upload()
152 scoped_guard(spinlock_irq, &dev->event_lock) { in input_ff_upload()
153 ff->effects[id] = *effect; in input_ff_upload()
154 ff->effect_owners[id] = file; in input_ff_upload()
168 struct ff_device *ff = dev->ff; in erase_effect()
169 int error; in erase_effect() local
171 error = check_effect_access(ff, effect_id, file); in erase_effect()
172 if (error) in erase_effect()
173 return error; in erase_effect()
175 scoped_guard(spinlock_irq, &dev->event_lock) { in erase_effect()
176 ff->playback(dev, effect_id, 0); in erase_effect()
177 ff->effect_owners[effect_id] = NULL; in erase_effect()
180 if (ff->erase) { in erase_effect()
181 error = ff->erase(dev, effect_id); in erase_effect()
182 if (error) { in erase_effect()
183 scoped_guard(spinlock_irq, &dev->event_lock) in erase_effect()
184 ff->effect_owners[effect_id] = file; in erase_effect()
186 return error; in erase_effect()
194 * input_ff_erase - erase a force-feedback effect from device
196 * @effect_id: id of the effect to be erased
199 * This function erases a force-feedback effect from specified device.
205 struct ff_device *ff = dev->ff; in input_ff_erase()
207 if (!test_bit(EV_FF, dev->evbit)) in input_ff_erase()
208 return -ENOSYS; in input_ff_erase()
210 guard(mutex)(&ff->mutex); in input_ff_erase()
216 * input_ff_flush - erase all effects owned by a file handle
220 * This function erases all force-feedback effects associated with
226 struct ff_device *ff = dev->ff; in input_ff_flush()
229 dev_dbg(&dev->dev, "flushing now\n"); in input_ff_flush()
231 guard(mutex)(&ff->mutex); in input_ff_flush()
233 for (i = 0; i < ff->max_effects; i++) in input_ff_flush()
241 * input_ff_event() - generic handler for force-feedback events
250 struct ff_device *ff = dev->ff; in input_ff_event()
257 if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffffU) in input_ff_event()
260 ff->set_gain(dev, value); in input_ff_event()
264 if (!test_bit(FF_AUTOCENTER, dev->ffbit) || value > 0xffffU) in input_ff_event()
267 ff->set_autocenter(dev, value); in input_ff_event()
272 ff->playback(dev, code, value); in input_ff_event()
281 * input_ff_create() - create force-feedback device
282 * @dev: input device supporting force-feedback
287 * @dev->ffbit should be already set up before calling this function.
296 dev_err(&dev->dev, "cannot allocate device without any effects\n"); in input_ff_create()
297 return -EINVAL; in input_ff_create()
301 dev_err(&dev->dev, "cannot allocate more than FF_MAX_EFFECTS effects\n"); in input_ff_create()
302 return -EINVAL; in input_ff_create()
308 return -ENOMEM; in input_ff_create()
310 ff->effects = kzalloc_objs(*ff->effects, max_effects); in input_ff_create()
311 if (!ff->effects) in input_ff_create()
312 return -ENOMEM; in input_ff_create()
314 ff->max_effects = max_effects; in input_ff_create()
315 mutex_init(&ff->mutex); in input_ff_create()
317 dev->flush = input_ff_flush; in input_ff_create()
318 dev->event = input_ff_event; in input_ff_create()
319 __set_bit(EV_FF, dev->evbit); in input_ff_create()
322 for_each_set_bit(i, dev->ffbit, FF_CNT) in input_ff_create()
323 __set_bit(i, ff->ffbit); in input_ff_create()
326 if (test_bit(FF_PERIODIC, ff->ffbit)) in input_ff_create()
327 __set_bit(FF_RUMBLE, dev->ffbit); in input_ff_create()
329 dev->ff = no_free_ptr(ff); in input_ff_create()
336 * input_ff_destroy() - frees force feedback portion of input device
339 * This function is only needed in error path as input core will
345 struct ff_device *ff = dev->ff; in input_ff_destroy()
347 __clear_bit(EV_FF, dev->evbit); in input_ff_destroy()
349 if (ff->destroy) in input_ff_destroy()
350 ff->destroy(ff); in input_ff_destroy()
351 kfree(ff->private); in input_ff_destroy()
352 kfree(ff->effects); in input_ff_destroy()
354 dev->ff = NULL; in input_ff_destroy()