lkml.org 
[lkml]   [2015]   [Jun]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 1/5] ipc,shm: move BUG_ON check into shm_lock
On Sat,  6 Jun 2015 06:37:56 -0700 Davidlohr Bueso <dave@stgolabs.net> wrote:

> Upon every shm_lock call, we BUG_ON if an error was returned,
> indicating racing either in idr or in shm_destroy. Move this logic
> into the locking.
>
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -155,8 +155,14 @@ static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id)
> {
> struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id);
>
> - if (IS_ERR(ipcp))
> + if (IS_ERR(ipcp)) {
> + /*
> + * We raced in the idr lookup or with shm_destroy(),
> + * either way, the ID is busted.
> + */
> + BUG();
> return (struct shmid_kernel *)ipcp;
> + }

Was there any particular reason to still do it this way? It's a bit
klunky.

--- a/ipc/shm.c~ipcshm-move-bug_on-check-into-shm_lock-fix
+++ a/ipc/shm.c
@@ -155,14 +155,11 @@ static inline struct shmid_kernel *shm_l
{
struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id);

- if (IS_ERR(ipcp)) {
- /*
- * We raced in the idr lookup or with shm_destroy(),
- * either way, the ID is busted.
- */
- BUG();
- return (struct shmid_kernel *)ipcp;
- }
+ /*
+ * We raced in the idr lookup or with shm_destroy(). Either way, the
+ * ID is busted.
+ */
+ BUG_ON(IS_ERR(ipcp));

return container_of(ipcp, struct shmid_kernel, shm_perm);
}
One benefit of the code you sent is that the unreachable `return' will
prevent a compile warning when CONFIG_BUG=n, but CONFIG_BUG=n is silly
and I never worry about it.


\
 
 \ /
  Last update: 2015-06-10 00:41    [W:0.061 / U:2.368 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site