Re: [PATCH v3 04/18] video/hdmi: Constify infoframe passed to the pack functions

2018-10-02 Thread Hans Verkuil
On 10/01/2018 09:10 PM, Ville Syrjälä wrote:
> On Fri, Sep 21, 2018 at 05:33:32PM +0300, Ville Syrjala wrote:
>> From: Ville Syrjälä 
>>
>> Let's make the infoframe pack functions usable with a const infoframe
>> structure. This allows us to precompute the infoframe earlier, and still
>> pack it later when we're no longer allowed to modify the structure.
>> So now we end up with a _check()+_pack_only() or _pack() functions
>> depending on whether you want to precompute the infoframes or not.
>> The names aren't great but I was lazy and didn't want to change all the
>> drivers.
>>
>> v2: Deal with exynos churn
>> Actually export the new funcs
>> v3: Fix various documentation fails (Hans)
> 
> Hans, any more concerns about this patch?

Acked-by: Hans Verkuil 

Regards,

Hans

> 
>>
>> Cc: Thierry Reding 
>> Cc: Hans Verkuil 
>> Cc: linux-me...@vger.kernel.org
>> Signed-off-by: Ville Syrjälä 
>> ---
>>  drivers/video/hdmi.c | 425 
>> +++
>>  include/linux/hdmi.h |  19 ++-
>>  2 files changed, 416 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
>> index 53e7ee2c83fc..08d94ab00467 100644
>> --- a/drivers/video/hdmi.c
>> +++ b/drivers/video/hdmi.c
>> @@ -68,8 +68,36 @@ int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe 
>> *frame)
>>  }
>>  EXPORT_SYMBOL(hdmi_avi_infoframe_init);
>>  
>> +static int hdmi_avi_infoframe_check_only(const struct hdmi_avi_infoframe 
>> *frame)
>> +{
>> +if (frame->type != HDMI_INFOFRAME_TYPE_AVI ||
>> +frame->version != 2 ||
>> +frame->length != HDMI_AVI_INFOFRAME_SIZE)
>> +return -EINVAL;
>> +
>> +if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
>> +return -EINVAL;
>> +
>> +return 0;
>> +}
>> +
>>  /**
>> - * hdmi_avi_infoframe_pack() - write HDMI AVI infoframe to binary buffer
>> + * hdmi_avi_infoframe_check() - check a HDMI AVI infoframe
>> + * @frame: HDMI AVI infoframe
>> + *
>> + * Validates that the infoframe is consistent and updates derived fields
>> + * (eg. length) based on other fields.
>> + *
>> + * Returns 0 on success or a negative error code on failure.
>> + */
>> +int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame)
>> +{
>> +return hdmi_avi_infoframe_check_only(frame);
>> +}
>> +EXPORT_SYMBOL(hdmi_avi_infoframe_check);
>> +
>> +/**
>> + * hdmi_avi_infoframe_pack_only() - write HDMI AVI infoframe to binary 
>> buffer
>>   * @frame: HDMI AVI infoframe
>>   * @buffer: destination buffer
>>   * @size: size of buffer
>> @@ -82,20 +110,22 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_init);
>>   * Returns the number of bytes packed into the binary buffer or a negative
>>   * error code on failure.
>>   */
>> -ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void 
>> *buffer,
>> -size_t size)
>> +ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
>> + void *buffer, size_t size)
>>  {
>>  u8 *ptr = buffer;
>>  size_t length;
>> +int ret;
>> +
>> +ret = hdmi_avi_infoframe_check_only(frame);
>> +if (ret)
>> +return ret;
>>  
>>  length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
>>  
>>  if (size < length)
>>  return -ENOSPC;
>>  
>> -if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
>> -return -EINVAL;
>> -
>>  memset(buffer, 0, size);
>>  
>>  ptr[0] = frame->type;
>> @@ -152,6 +182,36 @@ ssize_t hdmi_avi_infoframe_pack(struct 
>> hdmi_avi_infoframe *frame, void *buffer,
>>  
>>  return length;
>>  }
>> +EXPORT_SYMBOL(hdmi_avi_infoframe_pack_only);
>> +
>> +/**
>> + * hdmi_avi_infoframe_pack() - check a HDMI AVI infoframe,
>> + * and write it to binary buffer
>> + * @frame: HDMI AVI infoframe
>> + * @buffer: destination buffer
>> + * @size: size of buffer
>> + *
>> + * Validates that the infoframe is consistent and updates derived fields
>> + * (eg. length) based on other fields, after which it packs the information
>> + * contained in the @frame structure into a binary representation that
>> + * can be written into the corresponding controller registers. This function
>> + * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
>> + * specification.
>> + *
>> + * Returns the number of bytes packed into the binary buffer or a negative
>> + * error code on failure.
>> + */
>> +ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame,
>> +void *buffer, size_t size)
>> +{
>> +int ret;
>> +
>> +ret = hdmi_avi_infoframe_check(frame);
>> +if (ret)
>> +return ret;
>> +
>> +return hdmi_avi_infoframe_pack_only(frame, buffer, size);
>> +}
>>  EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
>>  
>>  /**
>> @@ -178,8 +238,33 @@ int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe 
>> *frame,
>>  }
>>  

Re: [PATCH v3 04/18] video/hdmi: Constify infoframe passed to the pack functions

2018-10-01 Thread Ville Syrjälä
On Fri, Sep 21, 2018 at 05:33:32PM +0300, Ville Syrjala wrote:
> From: Ville Syrjälä 
> 
> Let's make the infoframe pack functions usable with a const infoframe
> structure. This allows us to precompute the infoframe earlier, and still
> pack it later when we're no longer allowed to modify the structure.
> So now we end up with a _check()+_pack_only() or _pack() functions
> depending on whether you want to precompute the infoframes or not.
> The names aren't great but I was lazy and didn't want to change all the
> drivers.
> 
> v2: Deal with exynos churn
> Actually export the new funcs
> v3: Fix various documentation fails (Hans)

Hans, any more concerns about this patch?

> 
> Cc: Thierry Reding 
> Cc: Hans Verkuil 
> Cc: linux-me...@vger.kernel.org
> Signed-off-by: Ville Syrjälä 
> ---
>  drivers/video/hdmi.c | 425 
> +++
>  include/linux/hdmi.h |  19 ++-
>  2 files changed, 416 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
> index 53e7ee2c83fc..08d94ab00467 100644
> --- a/drivers/video/hdmi.c
> +++ b/drivers/video/hdmi.c
> @@ -68,8 +68,36 @@ int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe 
> *frame)
>  }
>  EXPORT_SYMBOL(hdmi_avi_infoframe_init);
>  
> +static int hdmi_avi_infoframe_check_only(const struct hdmi_avi_infoframe 
> *frame)
> +{
> + if (frame->type != HDMI_INFOFRAME_TYPE_AVI ||
> + frame->version != 2 ||
> + frame->length != HDMI_AVI_INFOFRAME_SIZE)
> + return -EINVAL;
> +
> + if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
> + return -EINVAL;
> +
> + return 0;
> +}
> +
>  /**
> - * hdmi_avi_infoframe_pack() - write HDMI AVI infoframe to binary buffer
> + * hdmi_avi_infoframe_check() - check a HDMI AVI infoframe
> + * @frame: HDMI AVI infoframe
> + *
> + * Validates that the infoframe is consistent and updates derived fields
> + * (eg. length) based on other fields.
> + *
> + * Returns 0 on success or a negative error code on failure.
> + */
> +int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame)
> +{
> + return hdmi_avi_infoframe_check_only(frame);
> +}
> +EXPORT_SYMBOL(hdmi_avi_infoframe_check);
> +
> +/**
> + * hdmi_avi_infoframe_pack_only() - write HDMI AVI infoframe to binary buffer
>   * @frame: HDMI AVI infoframe
>   * @buffer: destination buffer
>   * @size: size of buffer
> @@ -82,20 +110,22 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_init);
>   * Returns the number of bytes packed into the binary buffer or a negative
>   * error code on failure.
>   */
> -ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void 
> *buffer,
> - size_t size)
> +ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
> +  void *buffer, size_t size)
>  {
>   u8 *ptr = buffer;
>   size_t length;
> + int ret;
> +
> + ret = hdmi_avi_infoframe_check_only(frame);
> + if (ret)
> + return ret;
>  
>   length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
>  
>   if (size < length)
>   return -ENOSPC;
>  
> - if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
> - return -EINVAL;
> -
>   memset(buffer, 0, size);
>  
>   ptr[0] = frame->type;
> @@ -152,6 +182,36 @@ ssize_t hdmi_avi_infoframe_pack(struct 
> hdmi_avi_infoframe *frame, void *buffer,
>  
>   return length;
>  }
> +EXPORT_SYMBOL(hdmi_avi_infoframe_pack_only);
> +
> +/**
> + * hdmi_avi_infoframe_pack() - check a HDMI AVI infoframe,
> + * and write it to binary buffer
> + * @frame: HDMI AVI infoframe
> + * @buffer: destination buffer
> + * @size: size of buffer
> + *
> + * Validates that the infoframe is consistent and updates derived fields
> + * (eg. length) based on other fields, after which it packs the information
> + * contained in the @frame structure into a binary representation that
> + * can be written into the corresponding controller registers. This function
> + * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
> + * specification.
> + *
> + * Returns the number of bytes packed into the binary buffer or a negative
> + * error code on failure.
> + */
> +ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame,
> + void *buffer, size_t size)
> +{
> + int ret;
> +
> + ret = hdmi_avi_infoframe_check(frame);
> + if (ret)
> + return ret;
> +
> + return hdmi_avi_infoframe_pack_only(frame, buffer, size);
> +}
>  EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
>  
>  /**
> @@ -178,8 +238,33 @@ int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe 
> *frame,
>  }
>  EXPORT_SYMBOL(hdmi_spd_infoframe_init);
>  
> +static int hdmi_spd_infoframe_check_only(const struct hdmi_spd_infoframe 
> *frame)
> +{
> + if (frame->type != HDMI_INFOFRAME_TYPE_SPD ||
> + frame->version != 1 ||
> + 

[PATCH v3 04/18] video/hdmi: Constify infoframe passed to the pack functions

2018-09-21 Thread Ville Syrjala
From: Ville Syrjälä 

Let's make the infoframe pack functions usable with a const infoframe
structure. This allows us to precompute the infoframe earlier, and still
pack it later when we're no longer allowed to modify the structure.
So now we end up with a _check()+_pack_only() or _pack() functions
depending on whether you want to precompute the infoframes or not.
The names aren't great but I was lazy and didn't want to change all the
drivers.

v2: Deal with exynos churn
Actually export the new funcs
v3: Fix various documentation fails (Hans)

Cc: Thierry Reding 
Cc: Hans Verkuil 
Cc: linux-me...@vger.kernel.org
Signed-off-by: Ville Syrjälä 
---
 drivers/video/hdmi.c | 425 +++
 include/linux/hdmi.h |  19 ++-
 2 files changed, 416 insertions(+), 28 deletions(-)

diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
index 53e7ee2c83fc..08d94ab00467 100644
--- a/drivers/video/hdmi.c
+++ b/drivers/video/hdmi.c
@@ -68,8 +68,36 @@ int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame)
 }
 EXPORT_SYMBOL(hdmi_avi_infoframe_init);
 
+static int hdmi_avi_infoframe_check_only(const struct hdmi_avi_infoframe 
*frame)
+{
+   if (frame->type != HDMI_INFOFRAME_TYPE_AVI ||
+   frame->version != 2 ||
+   frame->length != HDMI_AVI_INFOFRAME_SIZE)
+   return -EINVAL;
+
+   if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
+   return -EINVAL;
+
+   return 0;
+}
+
 /**
- * hdmi_avi_infoframe_pack() - write HDMI AVI infoframe to binary buffer
+ * hdmi_avi_infoframe_check() - check a HDMI AVI infoframe
+ * @frame: HDMI AVI infoframe
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame)
+{
+   return hdmi_avi_infoframe_check_only(frame);
+}
+EXPORT_SYMBOL(hdmi_avi_infoframe_check);
+
+/**
+ * hdmi_avi_infoframe_pack_only() - write HDMI AVI infoframe to binary buffer
  * @frame: HDMI AVI infoframe
  * @buffer: destination buffer
  * @size: size of buffer
@@ -82,20 +110,22 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_init);
  * Returns the number of bytes packed into the binary buffer or a negative
  * error code on failure.
  */
-ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
-   size_t size)
+ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
+void *buffer, size_t size)
 {
u8 *ptr = buffer;
size_t length;
+   int ret;
+
+   ret = hdmi_avi_infoframe_check_only(frame);
+   if (ret)
+   return ret;
 
length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
 
if (size < length)
return -ENOSPC;
 
-   if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
-   return -EINVAL;
-
memset(buffer, 0, size);
 
ptr[0] = frame->type;
@@ -152,6 +182,36 @@ ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe 
*frame, void *buffer,
 
return length;
 }
+EXPORT_SYMBOL(hdmi_avi_infoframe_pack_only);
+
+/**
+ * hdmi_avi_infoframe_pack() - check a HDMI AVI infoframe,
+ * and write it to binary buffer
+ * @frame: HDMI AVI infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields, after which it packs the information
+ * contained in the @frame structure into a binary representation that
+ * can be written into the corresponding controller registers. This function
+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame,
+   void *buffer, size_t size)
+{
+   int ret;
+
+   ret = hdmi_avi_infoframe_check(frame);
+   if (ret)
+   return ret;
+
+   return hdmi_avi_infoframe_pack_only(frame, buffer, size);
+}
 EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
 
 /**
@@ -178,8 +238,33 @@ int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe 
*frame,
 }
 EXPORT_SYMBOL(hdmi_spd_infoframe_init);
 
+static int hdmi_spd_infoframe_check_only(const struct hdmi_spd_infoframe 
*frame)
+{
+   if (frame->type != HDMI_INFOFRAME_TYPE_SPD ||
+   frame->version != 1 ||
+   frame->length != HDMI_SPD_INFOFRAME_SIZE)
+   return -EINVAL;
+
+   return 0;
+}
+
 /**
- * hdmi_spd_infoframe_pack() - write HDMI SPD infoframe to binary buffer
+ * hdmi_spd_infoframe_check() - check a HDMI SPD infoframe
+ * @frame: HDMI SPD infoframe
+ *
+ * Validates that the infoframe is consistent and updates derived