Skip to content

Commit

Permalink
cdrom: gdrom: initialize global variable at init time
Browse files Browse the repository at this point in the history
commit 9183f01b5e6e32eb3f17b5f3f8d5ad5ac9786c49 upstream.

As Peter points out, if we were to disconnect and then reconnect this
driver from a device, the "global" state of the device would contain odd
values and could cause problems.  Fix this up by just initializing the
whole thing to 0 at probe() time.

Ideally this would be a per-device variable, but given the age and the
total lack of users of it, that would require a lot of s/./->/g changes
for really no good reason.

Reported-by: Peter Rosin <[email protected]>
Cc: Jens Axboe <[email protected]>
Reviewed-by: Peter Rosin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
gregkh committed May 26, 2021
1 parent 151881f commit 903bf81
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/cdrom/gdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,13 @@ static int probe_gdrom_setupqueue(void)
static int probe_gdrom(struct platform_device *devptr)
{
int err;

/*
* Ensure our "one" device is initialized properly in case of previous
* usages of it
*/
memset(&gd, 0, sizeof(gd));

/* Start the device */
if (gdrom_execute_diagnostic() != 1) {
pr_warning("ATA Probe for GDROM failed\n");
Expand Down Expand Up @@ -867,7 +874,7 @@ static struct platform_driver gdrom_driver = {
static int __init init_gdrom(void)
{
int rc;
gd.toc = NULL;

rc = platform_driver_register(&gdrom_driver);
if (rc)
return rc;
Expand Down

0 comments on commit 903bf81

Please sign in to comment.