@@ -10293,16 +10293,6 @@ int ufshcd_system_thaw(struct device *dev)
1029310293EXPORT_SYMBOL_GPL (ufshcd_system_thaw );
1029410294#endif /* CONFIG_PM_SLEEP */
1029510295
10296- /**
10297- * ufshcd_dealloc_host - deallocate Host Bus Adapter (HBA)
10298- * @hba: pointer to Host Bus Adapter (HBA)
10299- */
10300- void ufshcd_dealloc_host (struct ufs_hba * hba )
10301- {
10302- scsi_host_put (hba -> host );
10303- }
10304- EXPORT_SYMBOL_GPL (ufshcd_dealloc_host );
10305-
1030610296/**
1030710297 * ufshcd_set_dma_mask - Set dma mask based on the controller
1030810298 * addressing capability
@@ -10319,12 +10309,26 @@ static int ufshcd_set_dma_mask(struct ufs_hba *hba)
1031910309 return dma_set_mask_and_coherent (hba -> dev , DMA_BIT_MASK (32 ));
1032010310}
1032110311
10312+ /**
10313+ * ufshcd_devres_release - devres cleanup handler, invoked during release of
10314+ * hba->dev
10315+ * @host: pointer to SCSI host
10316+ */
10317+ static void ufshcd_devres_release (void * host )
10318+ {
10319+ scsi_host_put (host );
10320+ }
10321+
1032210322/**
1032310323 * ufshcd_alloc_host - allocate Host Bus Adapter (HBA)
1032410324 * @dev: pointer to device handle
1032510325 * @hba_handle: driver private handle
1032610326 *
1032710327 * Return: 0 on success, non-zero value on failure.
10328+ *
10329+ * NOTE: There is no corresponding ufshcd_dealloc_host() because this function
10330+ * keeps track of its allocations using devres and deallocates everything on
10331+ * device removal automatically.
1032810332 */
1032910333int ufshcd_alloc_host (struct device * dev , struct ufs_hba * * hba_handle )
1033010334{
@@ -10346,6 +10350,13 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle)
1034610350 err = - ENOMEM ;
1034710351 goto out_error ;
1034810352 }
10353+
10354+ err = devm_add_action_or_reset (dev , ufshcd_devres_release ,
10355+ host );
10356+ if (err )
10357+ return dev_err_probe (dev , err ,
10358+ "failed to add ufshcd dealloc action\n" );
10359+
1034910360 host -> nr_maps = HCTX_TYPE_POLL + 1 ;
1035010361 hba = shost_priv (host );
1035110362 hba -> host = host ;
0 commit comments