Print this page
XXXX cpudrv attach error handling is leaky


 297                         cpudrv_enabled = B_FALSE;
 298                         cpudrv_free(cpudsp);
 299                         ddi_soft_state_free(cpudrv_state, instance);
 300                         return (DDI_FAILURE);
 301                 }
 302                 if (ddi_prop_update_string(DDI_DEV_T_NONE,
 303                     dip, "pm-class", "CPU") != DDI_PROP_SUCCESS) {
 304                         cpudrv_enabled = B_FALSE;
 305                         cpudrv_free(cpudsp);
 306                         ddi_soft_state_free(cpudrv_state, instance);
 307                         return (DDI_FAILURE);
 308                 }
 309 
 310                 /*
 311                  * Taskq is used to dispatch routine to monitor CPU
 312                  * activities.
 313                  */
 314                 cpudsp->cpudrv_pm.tq = ddi_taskq_create(dip,
 315                     "cpudrv_monitor", CPUDRV_TASKQ_THREADS,
 316                     TASKQ_DEFAULTPRI, 0);






 317 
 318                 mutex_init(&cpudsp->cpudrv_pm.timeout_lock, NULL,
 319                     MUTEX_DRIVER, NULL);
 320                 cv_init(&cpudsp->cpudrv_pm.timeout_cv, NULL,
 321                     CV_DEFAULT, NULL);
 322 
 323                 /*
 324                  * Driver needs to assume that CPU is running at
 325                  * unknown speed at DDI_ATTACH and switch it to the
 326                  * needed speed. We assume that initial needed speed
 327                  * is full speed for us.
 328                  */
 329                 /*
 330                  * We need to take the lock because cpudrv_monitor()
 331                  * will start running in parallel with attach().
 332                  */
 333                 mutex_enter(&cpudsp->lock);
 334                 cpudsp->cpudrv_pm.cur_spd = NULL;
 335                 cpudsp->cpudrv_pm.pm_started = B_FALSE;
 336                 /*
 337                  * We don't call pm_raise_power() directly from attach
 338                  * because driver attach for a slave CPU node can
 339                  * happen before the CPU is even initialized. We just
 340                  * start the monitoring system which understands
 341                  * unknown speed and moves CPU to top speed when it
 342                  * has been initialized.
 343                  */
 344                 CPUDRV_MONITOR_INIT(cpudsp);
 345                 mutex_exit(&cpudsp->lock);
 346 
 347                 if (!cpudrv_mach_init(cpudsp)) {
 348                         cmn_err(CE_WARN, "cpudrv_attach: instance %d: "
 349                             "cpudrv_mach_init failed", instance);
 350                         cpudrv_enabled = B_FALSE;

 351                         cpudrv_free(cpudsp);
 352                         ddi_soft_state_free(cpudrv_state, instance);
 353                         return (DDI_FAILURE);
 354                 }
 355 
 356                 CPUDRV_INSTALL_MAX_CHANGE_HANDLER(cpudsp);
 357 
 358                 (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip,
 359                     DDI_NO_AUTODETACH, 1);
 360                 ddi_report_dev(dip);
 361                 return (DDI_SUCCESS);
 362 
 363         case DDI_RESUME:
 364                 DPRINTF(D_ATTACH, ("cpudrv_attach: instance %d: "
 365                     "DDI_RESUME called\n", instance));
 366 
 367                 cpudsp = ddi_get_soft_state(cpudrv_state, instance);
 368                 ASSERT(cpudsp != NULL);
 369 
 370                 /*




 297                         cpudrv_enabled = B_FALSE;
 298                         cpudrv_free(cpudsp);
 299                         ddi_soft_state_free(cpudrv_state, instance);
 300                         return (DDI_FAILURE);
 301                 }
 302                 if (ddi_prop_update_string(DDI_DEV_T_NONE,
 303                     dip, "pm-class", "CPU") != DDI_PROP_SUCCESS) {
 304                         cpudrv_enabled = B_FALSE;
 305                         cpudrv_free(cpudsp);
 306                         ddi_soft_state_free(cpudrv_state, instance);
 307                         return (DDI_FAILURE);
 308                 }
 309 
 310                 /*
 311                  * Taskq is used to dispatch routine to monitor CPU
 312                  * activities.
 313                  */
 314                 cpudsp->cpudrv_pm.tq = ddi_taskq_create(dip,
 315                     "cpudrv_monitor", CPUDRV_TASKQ_THREADS,
 316                     TASKQ_DEFAULTPRI, 0);
 317                 if (cpudsp->cpudrv_pm.tq == NULL) {
 318                         cpudrv_enabled = B_FALSE;
 319                         cpudrv_free(cpudsp);
 320                         ddi_soft_state_free(cpudrv_state, instance);
 321                         return (DDI_FAILURE);
 322                 }
 323 
 324                 mutex_init(&cpudsp->cpudrv_pm.timeout_lock, NULL,
 325                     MUTEX_DRIVER, NULL);
 326                 cv_init(&cpudsp->cpudrv_pm.timeout_cv, NULL,
 327                     CV_DEFAULT, NULL);
 328 
 329                 /*
 330                  * Driver needs to assume that CPU is running at
 331                  * unknown speed at DDI_ATTACH and switch it to the
 332                  * needed speed. We assume that initial needed speed
 333                  * is full speed for us.
 334                  */
 335                 /*
 336                  * We need to take the lock because cpudrv_monitor()
 337                  * will start running in parallel with attach().
 338                  */
 339                 mutex_enter(&cpudsp->lock);
 340                 cpudsp->cpudrv_pm.cur_spd = NULL;
 341                 cpudsp->cpudrv_pm.pm_started = B_FALSE;
 342                 /*
 343                  * We don't call pm_raise_power() directly from attach
 344                  * because driver attach for a slave CPU node can
 345                  * happen before the CPU is even initialized. We just
 346                  * start the monitoring system which understands
 347                  * unknown speed and moves CPU to top speed when it
 348                  * has been initialized.
 349                  */
 350                 CPUDRV_MONITOR_INIT(cpudsp);
 351                 mutex_exit(&cpudsp->lock);
 352 
 353                 if (!cpudrv_mach_init(cpudsp)) {
 354                         cmn_err(CE_WARN, "cpudrv_attach: instance %d: "
 355                             "cpudrv_mach_init failed", instance);
 356                         cpudrv_enabled = B_FALSE;
 357                         ddi_taskq_destroy(cpudsp->cpudrv_pm.tq);
 358                         cpudrv_free(cpudsp);
 359                         ddi_soft_state_free(cpudrv_state, instance);
 360                         return (DDI_FAILURE);
 361                 }
 362 
 363                 CPUDRV_INSTALL_MAX_CHANGE_HANDLER(cpudsp);
 364 
 365                 (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip,
 366                     DDI_NO_AUTODETACH, 1);
 367                 ddi_report_dev(dip);
 368                 return (DDI_SUCCESS);
 369 
 370         case DDI_RESUME:
 371                 DPRINTF(D_ATTACH, ("cpudrv_attach: instance %d: "
 372                     "DDI_RESUME called\n", instance));
 373 
 374                 cpudsp = ddi_get_soft_state(cpudrv_state, instance);
 375                 ASSERT(cpudsp != NULL);
 376 
 377                 /*