Skip to content

Commit 21b0dc5

Browse files
committed
driver core: faux: only create the device if probe() succeeds
It's really hard to know if a faux device properly passes the callback to probe() without having to poke around in the faux_device structure and then clean up. Instead of having to have every user of the api do this logic, just do it in the faux device core itself. This makes the use of a custom probe() callback for a faux device much simpler overall. Suggested-by: Kurt Borja <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Reviewed-by: Kurt Borja <[email protected]> Reviewed-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/2025022545-unroasted-common-fa0e@gregkh Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 95cb0cb commit 21b0dc5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/base/faux.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ static void faux_device_release(struct device *dev)
102102
*
103103
* Note, when this function is called, the functions specified in struct
104104
* faux_ops can be called before the function returns, so be prepared for
105-
* everything to be properly initialized before that point in time.
105+
* everything to be properly initialized before that point in time. If the
106+
* probe callback (if one is present) does NOT succeed, the creation of the
107+
* device will fail and NULL will be returned.
106108
*
107109
* Return:
108110
* * NULL if an error happened with creating the device
@@ -147,6 +149,17 @@ struct faux_device *faux_device_create_with_groups(const char *name,
147149
return NULL;
148150
}
149151

152+
/*
153+
* Verify that we did bind the driver to the device (i.e. probe worked),
154+
* if not, let's fail the creation as trying to guess if probe was
155+
* successful is almost impossible to determine by the caller.
156+
*/
157+
if (!dev->driver) {
158+
dev_err(dev, "probe did not succeed, tearing down the device\n");
159+
faux_device_destroy(faux_dev);
160+
faux_dev = NULL;
161+
}
162+
150163
return faux_dev;
151164
}
152165
EXPORT_SYMBOL_GPL(faux_device_create_with_groups);

0 commit comments

Comments
 (0)