public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [bug report] cross-tree: phase out dma_zalloc_coherent()
@ 2021-08-12 15:09 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2021-08-12 15:09 UTC (permalink / raw)
  Cc: linux-scsi

Ancient code leads to this static checker warning:

	drivers/scsi/mvumi.c:130 mvumi_alloc_mem_resource()
	warn: sleeping in atomic context

drivers/scsi/mvumi.c
    106 static struct mvumi_res *mvumi_alloc_mem_resource(struct mvumi_hba *mhba,
    107 				enum resource_type type, unsigned int size)
    108 {
    109 	struct mvumi_res *res = kzalloc(sizeof(*res), GFP_ATOMIC);
                                                              ^^^^^^^^^^
These allocations are atomic.

    110 
    111 	if (!res) {
    112 		dev_err(&mhba->pdev->dev,
    113 			"Failed to allocate memory for resource manager.\n");
    114 		return NULL;
    115 	}
    116 
    117 	switch (type) {
    118 	case RESOURCE_CACHED_MEMORY:
    119 		res->virt_addr = kzalloc(size, GFP_ATOMIC);
                                                       ^^^^^^^^^^

    120 		if (!res->virt_addr) {
    121 			dev_err(&mhba->pdev->dev,
    122 				"unable to allocate memory,size = %d.\n", size);
    123 			kfree(res);
    124 			return NULL;
    125 		}
    126 		break;
    127 
    128 	case RESOURCE_UNCACHED_MEMORY:
    129 		size = round_up(size, 8);
--> 130 		res->virt_addr = dma_alloc_coherent(&mhba->pdev->dev, size,
    131 						    &res->bus_addr,
    132 						    GFP_KERNEL);
                                                            ^^^^^^^^^^
Should this be as well?  The call tree is:

mvumi_isr_handler() <- disables preempt
-> mvumi_handshake()
   -> mvumi_init_data()
      -> mvumi_alloc_mem_resource()

    133 		if (!res->virt_addr) {
    134 			dev_err(&mhba->pdev->dev,
    135 					"unable to allocate consistent mem,"
    136 							"size = %d.\n", size);
    137 			kfree(res);
    138 			return NULL;
    139 		}
    140 		break;
    141 
    142 	default:
    143 		dev_err(&mhba->pdev->dev, "unknown resource type %d.\n", type);
    144 		kfree(res);
    145 		return NULL;
    146 	}
    147 
    148 	res->type = type;
    149 	res->size = size;
    150 	INIT_LIST_HEAD(&res->entry);
    151 	list_add_tail(&res->entry, &mhba->res_list);
    152 
    153 	return res;
    154 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-12 15:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-12 15:09 [bug report] cross-tree: phase out dma_zalloc_coherent() Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox