3232#define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ)
3333#define PARPORT_MIN_SPINTIME_VALUE 1
3434#define PARPORT_MAX_SPINTIME_VALUE 1000
35- /*
36- * PARPORT_BASE_* is the size of the known parts of the sysctl path
37- * in dev/partport/%s/devices/%s. "dev/parport/"(12), "/devices/"(9
38- * and null char(1).
39- */
40- #define PARPORT_BASE_PATH_SIZE 13
41- #define PARPORT_BASE_DEVICES_PATH_SIZE 22
4235
4336static int do_active_device (struct ctl_table * table , int write ,
4437 void * result , size_t * lenp , loff_t * ppos )
@@ -431,8 +424,7 @@ int parport_proc_register(struct parport *port)
431424{
432425 struct parport_sysctl_table * t ;
433426 char * tmp_dir_path ;
434- size_t tmp_path_len , port_name_len ;
435- int bytes_written , i , err = 0 ;
427+ int i , err = 0 ;
436428
437429 t = kmemdup (& parport_sysctl_template , sizeof (* t ), GFP_KERNEL );
438430 if (t == NULL )
@@ -446,35 +438,23 @@ int parport_proc_register(struct parport *port)
446438 t -> vars [5 + i ].extra2 = & port -> probe_info [i ];
447439 }
448440
449- port_name_len = strnlen (port -> name , PARPORT_NAME_MAX_LEN );
450- /*
451- * Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT/devices.
452- * We calculate for the second as that will give us enough for the first.
453- */
454- tmp_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len ;
455- tmp_dir_path = kzalloc (tmp_path_len , GFP_KERNEL );
441+ tmp_dir_path = kasprintf (GFP_KERNEL , "dev/parport/%s/devices" , port -> name );
456442 if (!tmp_dir_path ) {
457443 err = - ENOMEM ;
458444 goto exit_free_t ;
459445 }
460446
461- bytes_written = snprintf (tmp_dir_path , tmp_path_len ,
462- "dev/parport/%s/devices" , port -> name );
463- if (tmp_path_len <= bytes_written ) {
464- err = - ENOENT ;
465- goto exit_free_tmp_dir_path ;
466- }
467447 t -> devices_header = register_sysctl (tmp_dir_path , t -> device_dir );
468448 if (t -> devices_header == NULL ) {
469449 err = - ENOENT ;
470450 goto exit_free_tmp_dir_path ;
471451 }
472452
473- tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len ;
474- bytes_written = snprintf ( tmp_dir_path , tmp_path_len ,
475- "dev/parport/%s" , port -> name );
476- if (tmp_path_len <= bytes_written ) {
477- err = - ENOENT ;
453+ kfree ( tmp_dir_path ) ;
454+
455+ tmp_dir_path = kasprintf ( GFP_KERNEL , "dev/parport/%s" , port -> name );
456+ if (! tmp_dir_path ) {
457+ err = - ENOMEM ;
478458 goto unregister_devices_h ;
479459 }
480460
@@ -514,34 +494,22 @@ int parport_proc_unregister(struct parport *port)
514494
515495int parport_device_proc_register (struct pardevice * device )
516496{
517- int bytes_written , err = 0 ;
518497 struct parport_device_sysctl_table * t ;
519498 struct parport * port = device -> port ;
520- size_t port_name_len , device_name_len , tmp_dir_path_len ;
521499 char * tmp_dir_path ;
500+ int err = 0 ;
522501
523502 t = kmemdup (& parport_device_sysctl_template , sizeof (* t ), GFP_KERNEL );
524503 if (t == NULL )
525504 return - ENOMEM ;
526505
527- port_name_len = strnlen (port -> name , PARPORT_NAME_MAX_LEN );
528- device_name_len = strnlen (device -> name , PATH_MAX );
529-
530506 /* Allocate a buffer for two paths: dev/parport/PORT/devices/DEVICE. */
531- tmp_dir_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len + device_name_len ;
532- tmp_dir_path = kzalloc (tmp_dir_path_len , GFP_KERNEL );
507+ tmp_dir_path = kasprintf (GFP_KERNEL , "dev/parport/%s/devices/%s" , port -> name , device -> name );
533508 if (!tmp_dir_path ) {
534509 err = - ENOMEM ;
535510 goto exit_free_t ;
536511 }
537512
538- bytes_written = snprintf (tmp_dir_path , tmp_dir_path_len , "dev/parport/%s/devices/%s" ,
539- port -> name , device -> name );
540- if (tmp_dir_path_len <= bytes_written ) {
541- err = - ENOENT ;
542- goto exit_free_path ;
543- }
544-
545513 t -> vars [0 ].data = & device -> timeslice ;
546514
547515 t -> sysctl_header = register_sysctl (tmp_dir_path , t -> vars );
@@ -554,9 +522,6 @@ int parport_device_proc_register(struct pardevice *device)
554522 kfree (tmp_dir_path );
555523 return 0 ;
556524
557- exit_free_path :
558- kfree (tmp_dir_path );
559-
560525exit_free_t :
561526 kfree (t );
562527
0 commit comments