~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/speakup/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1283
1283
}
1284
1284
 
1285
1285
/* Allocation concurrency is protected by the console semaphore */
1286
 
void speakup_allocate(struct vc_data *vc)
 
1286
int speakup_allocate(struct vc_data *vc)
1287
1287
{
1288
1288
        int vc_num;
1289
1289
 
1292
1292
                speakup_console[vc_num] = kzalloc(sizeof(*speakup_console[0]),
1293
1293
                                                  GFP_ATOMIC);
1294
1294
                if (speakup_console[vc_num] == NULL)
1295
 
                        return;
 
1295
                        return -ENOMEM;
1296
1296
                speakup_date(vc);
1297
1297
        } else if (!spk_parked)
1298
1298
                speakup_date(vc);
 
1299
 
 
1300
        return 0;
1299
1301
}
1300
1302
 
1301
1303
void speakup_deallocate(struct vc_data *vc)
1303
1305
        int vc_num;
1304
1306
 
1305
1307
        vc_num = vc->vc_num;
1306
 
        if (speakup_console[vc_num] != NULL) {
1307
 
                kfree(speakup_console[vc_num]);
1308
 
                speakup_console[vc_num] = NULL;
1309
 
        }
 
1308
        kfree(speakup_console[vc_num]);
 
1309
        speakup_console[vc_num] = NULL;
1310
1310
}
1311
1311
 
1312
1312
static u_char is_cursor;
2217
2217
{
2218
2218
        int i;
2219
2219
 
2220
 
        free_user_msgs();
2221
2220
        unregister_keyboard_notifier(&keyboard_notifier_block);
2222
2221
        unregister_vt_notifier(&vt_notifier_block);
2223
2222
        speakup_unregister_devsynth();
2224
2223
        del_timer(&cursor_timer);
2225
 
 
2226
2224
        kthread_stop(speakup_task);
2227
2225
        speakup_task = NULL;
2228
2226
        mutex_lock(&spk_mutex);
2229
2227
        synth_release();
2230
2228
        mutex_unlock(&spk_mutex);
2231
2229
 
 
2230
        speakup_kobj_exit();
 
2231
 
 
2232
        for (i = 0; i < MAX_NR_CONSOLES; i++)
 
2233
                kfree(speakup_console[i]);
 
2234
 
 
2235
        speakup_remove_virtual_keyboard();
 
2236
 
2232
2237
        for (i = 0; i < MAXVARS; i++)
2233
2238
                speakup_unregister_var(i);
2234
2239
 
2236
2241
                if (characters[i] != default_chars[i])
2237
2242
                        kfree(characters[i]);
2238
2243
        }
2239
 
        for (i = 0; speakup_console[i]; i++)
2240
 
                kfree(speakup_console[i]);
2241
 
        speakup_kobj_exit();
2242
 
        speakup_remove_virtual_keyboard();
 
2244
 
 
2245
        free_user_msgs();
2243
2246
}
2244
2247
 
2245
2248
/* call by: module_init() */
2246
2249
static int __init speakup_init(void)
2247
2250
{
2248
2251
        int i;
2249
 
        int err;
 
2252
        long err = 0;
2250
2253
        struct st_spk_t *first_console;
2251
2254
        struct vc_data *vc = vc_cons[fg_console].d;
2252
2255
        struct var_t *var;
2253
2256
 
2254
 
        err = speakup_add_virtual_keyboard();
2255
 
        if (err)
2256
 
                goto out;
2257
 
 
 
2257
        /* These first few initializations cannot fail. */
2258
2258
        initialize_msgs();      /* Initialize arrays for i18n. */
2259
 
        first_console = kzalloc(sizeof(*first_console), GFP_KERNEL);
2260
 
        if (!first_console) {
2261
 
                err = -ENOMEM;
2262
 
                goto err_cons;
2263
 
        }
2264
 
        err = speakup_kobj_init();
2265
 
        if (err)
2266
 
                goto err_kobject;
2267
 
 
2268
2259
        reset_default_chars();
2269
2260
        reset_default_chartab();
2270
 
 
2271
 
        speakup_console[vc->vc_num] = first_console;
2272
 
        speakup_date(vc);
2273
 
        pr_info("speakup %s: initialized\n", SPEAKUP_VERSION);
2274
 
 
2275
2261
        strlwr(synth_name);
2276
2262
        spk_vars[0].u.n.high = vc->vc_cols;
2277
2263
        for (var = spk_vars; var->var_id != MAXVARS; var++)
2286
2272
        if (quiet_boot)
2287
2273
                spk_shut_up |= 0x01;
2288
2274
 
 
2275
        /* From here on out, initializations can fail. */
 
2276
        err = speakup_add_virtual_keyboard();
 
2277
        if (err)
 
2278
                goto error_virtkeyboard;
 
2279
 
 
2280
        first_console = kzalloc(sizeof(*first_console), GFP_KERNEL);
 
2281
        if (!first_console) {
 
2282
                err = -ENOMEM;
 
2283
                goto error_alloc;
 
2284
        }
 
2285
 
 
2286
        speakup_console[vc->vc_num] = first_console;
 
2287
        speakup_date(vc);
 
2288
 
2289
2289
        for (i = 0; i < MAX_NR_CONSOLES; i++)
2290
 
                if (vc_cons[i].d)
2291
 
                        speakup_allocate(vc_cons[i].d);
2292
 
 
2293
 
        pr_warn("synth name on entry is: %s\n", synth_name);
 
2290
                if (vc_cons[i].d) {
 
2291
                        err = speakup_allocate(vc_cons[i].d);
 
2292
                        if (err)
 
2293
                                goto error_kobjects;
 
2294
                }
 
2295
 
 
2296
        err = speakup_kobj_init();
 
2297
        if (err)
 
2298
                goto error_kobjects;
 
2299
 
2294
2300
        synth_init(synth_name);
2295
2301
        speakup_register_devsynth();
 
2302
        /*
 
2303
         * register_devsynth might fail, but this error is not fatal.
 
2304
         * /dev/synth is an extra feature; the rest of Speakup
 
2305
         * will work fine without it.
 
2306
         */
2296
2307
 
2297
 
        register_keyboard_notifier(&keyboard_notifier_block);
2298
 
        register_vt_notifier(&vt_notifier_block);
 
2308
        err = register_keyboard_notifier(&keyboard_notifier_block);
 
2309
        if (err)
 
2310
                goto error_kbdnotifier;
 
2311
        err = register_vt_notifier(&vt_notifier_block);
 
2312
        if (err)
 
2313
                goto error_vtnotifier;
2299
2314
 
2300
2315
        speakup_task = kthread_create(speakup_thread, NULL, "speakup");
 
2316
 
 
2317
        if (IS_ERR(speakup_task)) {
 
2318
                err = PTR_ERR(speakup_task);
 
2319
                goto error_task;
 
2320
        }
 
2321
 
2301
2322
        set_user_nice(speakup_task, 10);
2302
 
        if (IS_ERR(speakup_task)) {
2303
 
                err = -ENOMEM;
2304
 
                goto err_kobject;
2305
 
        }
2306
2323
        wake_up_process(speakup_task);
 
2324
 
 
2325
        pr_info("speakup %s: initialized\n", SPEAKUP_VERSION);
 
2326
        pr_info("synth name on entry is: %s\n", synth_name);
2307
2327
        goto out;
2308
2328
 
2309
 
err_kobject:
2310
 
speakup_kobj_exit();
2311
 
        kfree(first_console);
2312
 
err_cons:
 
2329
error_task:
 
2330
        unregister_vt_notifier(&vt_notifier_block);
 
2331
 
 
2332
error_vtnotifier:
 
2333
        unregister_keyboard_notifier(&keyboard_notifier_block);
 
2334
        del_timer(&cursor_timer);
 
2335
 
 
2336
error_kbdnotifier:
 
2337
        speakup_unregister_devsynth();
 
2338
        mutex_lock(&spk_mutex);
 
2339
        synth_release();
 
2340
        mutex_unlock(&spk_mutex);
 
2341
        speakup_kobj_exit();
 
2342
 
 
2343
error_kobjects:
 
2344
        for (i = 0; i < MAX_NR_CONSOLES; i++)
 
2345
                kfree(speakup_console[i]);
 
2346
 
 
2347
error_alloc:
2313
2348
        speakup_remove_virtual_keyboard();
 
2349
 
 
2350
error_virtkeyboard:
 
2351
        for (i = 0; i < MAXVARS; i++)
 
2352
                speakup_unregister_var(i);
 
2353
 
 
2354
        for (i = 0; i < 256; i++) {
 
2355
                if (characters[i] != default_chars[i])
 
2356
                        kfree(characters[i]);
 
2357
        }
 
2358
 
 
2359
        free_user_msgs();
 
2360
 
2314
2361
out:
2315
2362
        return err;
2316
2363
}