public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: unlisted-recipients:; (no To-header on input)
Cc: linux-scsi@vger.kernel.org
Subject: [bug report] cross-tree: phase out dma_zalloc_coherent()
Date: Thu, 12 Aug 2021 18:09:55 +0300	[thread overview]
Message-ID: <20210812150954.GA18943@kili> (raw)

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

                 reply	other threads:[~2021-08-12 15:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210812150954.GA18943@kili \
    --to=dan.carpenter@oracle.com \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox