Message ID | 20240814-coccinelle-followup-v2-1-88b4e4a9af56@chromium.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | media: Follow-up for coccinelle lock fixes patchset | expand |
Hi On Wed, 14 Aug 2024 at 16:10, Ricardo Ribalda <ribalda@chromium.org> wrote: > > Move the actual opening to its own function. > > Not intended code change. This is a preparation for the next patch. > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > --- > drivers/media/dvb-core/dvb_frontend.c | 143 +++++++++++++++++----------------- > 1 file changed, 70 insertions(+), 73 deletions(-) > > diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c > index 4f78f30b3646..e81b9996530e 100644 > --- a/drivers/media/dvb-core/dvb_frontend.c > +++ b/drivers/media/dvb-core/dvb_frontend.c > @@ -2760,80 +2760,13 @@ static __poll_t dvb_frontend_poll(struct file *file, struct poll_table_struct *w > return 0; > } > > -static int dvb_frontend_open(struct inode *inode, struct file *file) > +static int __dvb_frontend_open(struct inode *inode, struct file *file) > { > struct dvb_device *dvbdev = file->private_data; > struct dvb_frontend *fe = dvbdev->priv; > struct dvb_frontend_private *fepriv = fe->frontend_priv; > - struct dvb_adapter *adapter = fe->dvb; > int ret; > > - dev_dbg(fe->dvb->device, "%s:\n", __func__); > - if (fe->exit == DVB_FE_DEVICE_REMOVED) > - return -ENODEV; > - > - if (adapter->mfe_shared == 2) { > - mutex_lock(&adapter->mfe_lock); > - if ((file->f_flags & O_ACCMODE) != O_RDONLY) { > - if (adapter->mfe_dvbdev && > - !adapter->mfe_dvbdev->writers) { > - mutex_unlock(&adapter->mfe_lock); > - return -EBUSY; > - } > - adapter->mfe_dvbdev = dvbdev; > - } > - } else if (adapter->mfe_shared) { > - mutex_lock(&adapter->mfe_lock); > - > - if (!adapter->mfe_dvbdev) > - adapter->mfe_dvbdev = dvbdev; > - > - else if (adapter->mfe_dvbdev != dvbdev) { > - struct dvb_device > - *mfedev = adapter->mfe_dvbdev; > - struct dvb_frontend > - *mfe = mfedev->priv; > - struct dvb_frontend_private > - *mfepriv = mfe->frontend_priv; > - int mferetry = (dvb_mfe_wait_time << 1); > - > - mutex_unlock(&adapter->mfe_lock); > - while (mferetry-- && (mfedev->users != -1 || > - mfepriv->thread)) { > - if (msleep_interruptible(500)) { > - if (signal_pending(current)) > - return -EINTR; > - } > - } > - > - mutex_lock(&adapter->mfe_lock); > - if (adapter->mfe_dvbdev != dvbdev) { > - mfedev = adapter->mfe_dvbdev; > - mfe = mfedev->priv; > - mfepriv = mfe->frontend_priv; > - if (mfedev->users != -1 || > - mfepriv->thread) { > - mutex_unlock(&adapter->mfe_lock); > - return -EBUSY; > - } > - adapter->mfe_dvbdev = dvbdev; > - } > - } > - } > - > - if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) { > - if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0) > - goto err0; > - > - /* If we took control of the bus, we need to force > - reinitialization. This is because many ts_bus_ctrl() > - functions strobe the RESET pin on the demod, and if the > - frontend thread already exists then the dvb_init() routine > - won't get called (which is what usually does initial > - register configuration). */ > - fepriv->reinitialise = 1; > - } This branch was missing in the patch. I will send a new version. Hopefuly someone with access to the hardware can test it? > - > if ((ret = dvb_generic_open(inode, file)) < 0) > goto err1; > > @@ -2871,8 +2804,6 @@ static int dvb_frontend_open(struct inode *inode, struct file *file) > > dvb_frontend_get(fe); > > - if (adapter->mfe_shared) > - mutex_unlock(&adapter->mfe_lock); > return ret; > > err3: > @@ -2891,9 +2822,75 @@ static int dvb_frontend_open(struct inode *inode, struct file *file) > err1: > if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) > fe->ops.ts_bus_ctrl(fe, 0); > -err0: > - if (adapter->mfe_shared) > - mutex_unlock(&adapter->mfe_lock); > + > + return ret; > +} > + > +static int dvb_frontend_open(struct inode *inode, struct file *file) > +{ > + struct dvb_device *dvbdev = file->private_data; > + struct dvb_frontend *fe = dvbdev->priv; > + struct dvb_adapter *adapter = fe->dvb; > + int ret; > + > + dev_dbg(fe->dvb->device, "%s:\n", __func__); > + if (fe->exit == DVB_FE_DEVICE_REMOVED) > + return -ENODEV; > + > + if (!adapter->mfe_shared) > + return __dvb_frontend_open(inode, file); > + > + if (adapter->mfe_shared == 2) { > + mutex_lock(&adapter->mfe_lock); > + if ((file->f_flags & O_ACCMODE) != O_RDONLY) { > + if (adapter->mfe_dvbdev && > + !adapter->mfe_dvbdev->writers) { > + mutex_unlock(&adapter->mfe_lock); > + return -EBUSY; > + } > + adapter->mfe_dvbdev = dvbdev; > + } > + } else { > + mutex_lock(&adapter->mfe_lock); > + > + if (!adapter->mfe_dvbdev) { > + adapter->mfe_dvbdev = dvbdev; > + } else if (adapter->mfe_dvbdev != dvbdev) { > + struct dvb_device > + *mfedev = adapter->mfe_dvbdev; > + struct dvb_frontend > + *mfe = mfedev->priv; > + struct dvb_frontend_private > + *mfepriv = mfe->frontend_priv; > + int mferetry = (dvb_mfe_wait_time << 1); > + > + mutex_unlock(&adapter->mfe_lock); > + while (mferetry-- && (mfedev->users != -1 || > + mfepriv->thread)) { > + if (msleep_interruptible(500)) { > + if (signal_pending(current)) > + return -EINTR; > + } > + } > + > + mutex_lock(&adapter->mfe_lock); > + if (adapter->mfe_dvbdev != dvbdev) { > + mfedev = adapter->mfe_dvbdev; > + mfe = mfedev->priv; > + mfepriv = mfe->frontend_priv; > + if (mfedev->users != -1 || > + mfepriv->thread) { > + mutex_unlock(&adapter->mfe_lock); > + return -EBUSY; > + } > + adapter->mfe_dvbdev = dvbdev; > + } > + } > + } > + > + ret = __dvb_frontend_open(inode, file); > + mutex_unlock(&adapter->mfe_lock); > + > return ret; > } > > > -- > 2.46.0.76.ge559c4bf1a-goog >
diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c index 4f78f30b3646..e81b9996530e 100644 --- a/drivers/media/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb-core/dvb_frontend.c @@ -2760,80 +2760,13 @@ static __poll_t dvb_frontend_poll(struct file *file, struct poll_table_struct *w return 0; } -static int dvb_frontend_open(struct inode *inode, struct file *file) +static int __dvb_frontend_open(struct inode *inode, struct file *file) { struct dvb_device *dvbdev = file->private_data; struct dvb_frontend *fe = dvbdev->priv; struct dvb_frontend_private *fepriv = fe->frontend_priv; - struct dvb_adapter *adapter = fe->dvb; int ret; - dev_dbg(fe->dvb->device, "%s:\n", __func__); - if (fe->exit == DVB_FE_DEVICE_REMOVED) - return -ENODEV; - - if (adapter->mfe_shared == 2) { - mutex_lock(&adapter->mfe_lock); - if ((file->f_flags & O_ACCMODE) != O_RDONLY) { - if (adapter->mfe_dvbdev && - !adapter->mfe_dvbdev->writers) { - mutex_unlock(&adapter->mfe_lock); - return -EBUSY; - } - adapter->mfe_dvbdev = dvbdev; - } - } else if (adapter->mfe_shared) { - mutex_lock(&adapter->mfe_lock); - - if (!adapter->mfe_dvbdev) - adapter->mfe_dvbdev = dvbdev; - - else if (adapter->mfe_dvbdev != dvbdev) { - struct dvb_device - *mfedev = adapter->mfe_dvbdev; - struct dvb_frontend - *mfe = mfedev->priv; - struct dvb_frontend_private - *mfepriv = mfe->frontend_priv; - int mferetry = (dvb_mfe_wait_time << 1); - - mutex_unlock(&adapter->mfe_lock); - while (mferetry-- && (mfedev->users != -1 || - mfepriv->thread)) { - if (msleep_interruptible(500)) { - if (signal_pending(current)) - return -EINTR; - } - } - - mutex_lock(&adapter->mfe_lock); - if (adapter->mfe_dvbdev != dvbdev) { - mfedev = adapter->mfe_dvbdev; - mfe = mfedev->priv; - mfepriv = mfe->frontend_priv; - if (mfedev->users != -1 || - mfepriv->thread) { - mutex_unlock(&adapter->mfe_lock); - return -EBUSY; - } - adapter->mfe_dvbdev = dvbdev; - } - } - } - - if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) { - if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0) - goto err0; - - /* If we took control of the bus, we need to force - reinitialization. This is because many ts_bus_ctrl() - functions strobe the RESET pin on the demod, and if the - frontend thread already exists then the dvb_init() routine - won't get called (which is what usually does initial - register configuration). */ - fepriv->reinitialise = 1; - } - if ((ret = dvb_generic_open(inode, file)) < 0) goto err1; @@ -2871,8 +2804,6 @@ static int dvb_frontend_open(struct inode *inode, struct file *file) dvb_frontend_get(fe); - if (adapter->mfe_shared) - mutex_unlock(&adapter->mfe_lock); return ret; err3: @@ -2891,9 +2822,75 @@ static int dvb_frontend_open(struct inode *inode, struct file *file) err1: if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) fe->ops.ts_bus_ctrl(fe, 0); -err0: - if (adapter->mfe_shared) - mutex_unlock(&adapter->mfe_lock); + + return ret; +} + +static int dvb_frontend_open(struct inode *inode, struct file *file) +{ + struct dvb_device *dvbdev = file->private_data; + struct dvb_frontend *fe = dvbdev->priv; + struct dvb_adapter *adapter = fe->dvb; + int ret; + + dev_dbg(fe->dvb->device, "%s:\n", __func__); + if (fe->exit == DVB_FE_DEVICE_REMOVED) + return -ENODEV; + + if (!adapter->mfe_shared) + return __dvb_frontend_open(inode, file); + + if (adapter->mfe_shared == 2) { + mutex_lock(&adapter->mfe_lock); + if ((file->f_flags & O_ACCMODE) != O_RDONLY) { + if (adapter->mfe_dvbdev && + !adapter->mfe_dvbdev->writers) { + mutex_unlock(&adapter->mfe_lock); + return -EBUSY; + } + adapter->mfe_dvbdev = dvbdev; + } + } else { + mutex_lock(&adapter->mfe_lock); + + if (!adapter->mfe_dvbdev) { + adapter->mfe_dvbdev = dvbdev; + } else if (adapter->mfe_dvbdev != dvbdev) { + struct dvb_device + *mfedev = adapter->mfe_dvbdev; + struct dvb_frontend + *mfe = mfedev->priv; + struct dvb_frontend_private + *mfepriv = mfe->frontend_priv; + int mferetry = (dvb_mfe_wait_time << 1); + + mutex_unlock(&adapter->mfe_lock); + while (mferetry-- && (mfedev->users != -1 || + mfepriv->thread)) { + if (msleep_interruptible(500)) { + if (signal_pending(current)) + return -EINTR; + } + } + + mutex_lock(&adapter->mfe_lock); + if (adapter->mfe_dvbdev != dvbdev) { + mfedev = adapter->mfe_dvbdev; + mfe = mfedev->priv; + mfepriv = mfe->frontend_priv; + if (mfedev->users != -1 || + mfepriv->thread) { + mutex_unlock(&adapter->mfe_lock); + return -EBUSY; + } + adapter->mfe_dvbdev = dvbdev; + } + } + } + + ret = __dvb_frontend_open(inode, file); + mutex_unlock(&adapter->mfe_lock); + return ret; }
Move the actual opening to its own function. Not intended code change. This is a preparation for the next patch. Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> --- drivers/media/dvb-core/dvb_frontend.c | 143 +++++++++++++++++----------------- 1 file changed, 70 insertions(+), 73 deletions(-)