Skip to content

Commit d676e37

Browse files
aishpantgregkh
authored andcommitted
staging: bcm2835-audio: replace null with error pointer value
This patch replaces NULL values returned by vc_vchi_audio_init(...) with error pointer values: - Return ERR_PTR(-EINVAL) when too many instances of audio service are initialised - Return ERR_PTR(-ENOMEM) when kzalloc fails - RETURN ERR_PTR(-EPERM) when vchi connections fail to open Similarly, a NULL check where vc_vchi_audio_init(...) is called is replaced by IS_ERR(..) Signed-off-by: Aishwarya Pant <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fc8612b commit d676e37

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,20 @@ vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
280280
unsigned int i;
281281
struct bcm2835_audio_instance *instance;
282282
int status;
283+
int ret;
283284

284285
LOG_DBG("%s: start", __func__);
285286

286287
if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
287288
LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
288289
__func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
289290

290-
return NULL;
291+
return ERR_PTR(-EINVAL);
291292
}
292293
/* Allocate memory for this instance */
293294
instance = kzalloc(sizeof(*instance), GFP_KERNEL);
294295
if (!instance)
295-
return NULL;
296+
return ERR_PTR(-ENOMEM);
296297

297298
instance->num_connections = num_connections;
298299

@@ -321,7 +322,7 @@ vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
321322
if (status) {
322323
LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n",
323324
__func__, status);
324-
325+
ret = -EPERM;
325326
goto err_close_services;
326327
}
327328
/* Finished with the service for now */
@@ -341,7 +342,7 @@ vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
341342
kfree(instance);
342343
LOG_ERR("%s: error\n", __func__);
343344

344-
return NULL;
345+
return ERR_PTR(ret);
345346
}
346347

347348
static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)
@@ -432,7 +433,7 @@ static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream
432433
/* Initialize an instance of the audio service */
433434
instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
434435

435-
if (!instance) {
436+
if (IS_ERR(instance)) {
436437
LOG_ERR("%s: failed to initialize audio service\n", __func__);
437438

438439
ret = -EPERM;

0 commit comments

Comments
 (0)