All of lore.kernel.org
 help / color / mirror / Atom feed
From: Satendra Singh Thakur <satendra.t@samsung.com>
To: alsa-devel@alsa-project.org
Cc: perex@perex.cz, tiwai@suse.com, o-takashi@sakamocchi.jp,
	linux-kernel@vger.kernel.org, hemanshu.s@samsung.com,
	nishant.s4@samsung.com, ycheon.song@samsung.com,
	satendra singh thakur <satendra.t@samsung.com>
Subject: [RFC] [ALSA][CONTROL] Restructured the code for read/write of  a single control
Date: Thu, 02 Feb 2017 08:55:50 +0530	[thread overview]
Message-ID: <1486005950-27735-1-git-send-email-satendra.t@samsung.com> (raw)
In-Reply-To: CGME20170202032617epcas1p13f71e6400d21aa5471fd671f31e6edd8@epcas1p1.samsung.com

From: satendra singh thakur <satendra.t@samsung.com>

-Restructured/Combined two functions snd_ctl_elem_read_user and
 snd_ctl_elem_write_user into a single function snd_ctl_elem_rw_user
-These functions were having most of the code which was similar
 to each other
-Thus, there was redundant/duplicate code which was removed
 and a single function was formed/defined.-
-Removed functions snd_ctl_elem_read_user and snd_ctl_elem_write_user
 having redundant/duplicate code

Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com>
---
 sound/core/control.c |   55 ++++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/sound/core/control.c b/sound/core/control.c
index fb096cb..6a8bc19 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -920,28 +920,6 @@ static int snd_ctl_elem_read(struct snd_card *card,
 	return result;
 }
 
-static int snd_ctl_elem_read_user(struct snd_card *card,
-				  struct snd_ctl_elem_value __user *_control)
-{
-	struct snd_ctl_elem_value *control;
-	int result;
-
-	control = memdup_user(_control, sizeof(*control));
-	if (IS_ERR(control))
-		return PTR_ERR(control);
-
-	snd_power_lock(card);
-	result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
-	if (result >= 0)
-		result = snd_ctl_elem_read(card, control);
-	snd_power_unlock(card);
-	if (result >= 0)
-		if (copy_to_user(_control, control, sizeof(*control)))
-			result = -EFAULT;
-	kfree(control);
-	return result;
-}
-
 static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
 			      struct snd_ctl_elem_value *control)
 {
@@ -976,22 +954,37 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
 	return result;
 }
 
-static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
-				   struct snd_ctl_elem_value __user *_control)
+
+/**
+ * snd_ctl_elem_rw_user - Read/write value of an element
+ * @file: the card to which element belongs to
+ * @_control,: the card to which element belongs to
+ * @card: the card to which element belongs to
+ * @pucontrols: user-space pointer to struct snd_ctl_elem_values
+ *
+ * This function reads the value of controls with the given IDs
+ * of the same card
+ */
+
+static int snd_ctl_elem_rw_user(struct snd_ctl_file *file,
+				  struct snd_ctl_elem_value __user *_control,
+			bool write_flag)
 {
 	struct snd_ctl_elem_value *control;
-	struct snd_card *card;
 	int result;
-
+	struct snd_card *card;
 	control = memdup_user(_control, sizeof(*control));
 	if (IS_ERR(control))
 		return PTR_ERR(control);
-
 	card = file->card;
 	snd_power_lock(card);
 	result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
-	if (result >= 0)
-		result = snd_ctl_elem_write(card, file, control);
+	if (result >= 0) {
+		if (write_flag == true)
+			result = snd_ctl_elem_write(card, file, control);
+		else
+			result = snd_ctl_elem_read(card, control);
+	}
 	snd_power_unlock(card);
 	if (result >= 0)
 		if (copy_to_user(_control, control, sizeof(*control)))
@@ -1514,9 +1507,9 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg
 	case SNDRV_CTL_IOCTL_ELEM_INFO:
 		return snd_ctl_elem_info_user(ctl, argp);
 	case SNDRV_CTL_IOCTL_ELEM_READ:
-		return snd_ctl_elem_read_user(card, argp);
+		return snd_ctl_elem_rw_user(ctl, argp, false);
 	case SNDRV_CTL_IOCTL_ELEM_WRITE:
-		return snd_ctl_elem_write_user(ctl, argp);
+		return snd_ctl_elem_rw_user(ctl, argp, true);
 	case SNDRV_CTL_IOCTL_ELEM_LOCK:
 		return snd_ctl_elem_lock(ctl, argp);
 	case SNDRV_CTL_IOCTL_ELEM_UNLOCK:
-- 
1.7.9.5

           reply	other threads:[~2017-02-02  3:26 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CGME20170202032617epcas1p13f71e6400d21aa5471fd671f31e6edd8@epcas1p1.samsung.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1486005950-27735-1-git-send-email-satendra.t@samsung.com \
    --to=satendra.t@samsung.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=hemanshu.s@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nishant.s4@samsung.com \
    --cc=o-takashi@sakamocchi.jp \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=ycheon.song@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.